Python 不上传正确的Firebase数据

2024-04-27 05:06:13 发布

您现在位置:Python中文网/ 问答频道 /正文

所以有一点背景信息:我从网站上搜集了一些数据

我声明了两个数组,一个数组有所有的团队名称(总共16个),另一个数组是times(它们总共有8个项)

在上传到Firebase之前,我想把所有这些信息放到字典中,所以基本上我需要先对数组进行排序。它的设置方式有一个偶数值的数组是第一队奇数值是对手

所以这意味着如果我要编一本字典,我可以:

{"teamone": teamNames[evenValue], "teamTwo": teamNames[oddValue]}

我还可以通过将times数组元素添加到字典中来附加时间,以便:

{"timeGameStarts": times[countOfIteration of whole array]}

所以我的代码是这样的:

teamObjects = {"TeamOne": "", "TeamTwo": "", "Time": ""}
matchPackage = [teamObjects]
print(len(teamNames))
countTwo = 0
for i in times:
    matchPackage.append(teamObjects)
    matchPackage[countTwo] = teamObjects["Time"] = times[countTwo]
    countTwo += 1

countThree = 0
count = 0
for l in teamNames:
    if count % 2 == 0:
        #even number
        matchPackage[countThree] = teamObjects["TeamOne"] = teamNames[count]
    else:
        matchPackage[countThree] = teamObjects["TeamTwo"] = teamNames[count]
        countThree += 1
    print(count)
    count += 1

我对Python语法一无所知,所以这只是猜测,但在最后一个元素之前,基本上会产生错误的结果。数组中的最后一个元素或元素8是每个元素的外观。真正奇怪的是Firebase中不应该有8个元素,应该是0到7

how it looks in the database

以下是所有团队价值观:

0: "Astralis"
1: "Virtus.pro"
2: "Virtus.pro"
3: "Astralis"
4: "Fnatic"
5: "Team EnVyUs"
6: "Team EnVyUs"
7: "Fnatic"
8: "Counter Logic Gaming"
9: "OpTic Gaming"
10: "OpTic Gaming"
11: "Counter Logic Gaming"
12: "Cloud9"
13: "Immortals"
14: "Immortals"
15: "Cloud9"

Tags: 信息元素字典count数组团队数值times