Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在列表列表中,如何确保一个列表中的列表元素不会与其他列表混合?_Python_List_Nested Lists - Fatal编程技术网

Python 在列表列表中,如何确保一个列表中的列表元素不会与其他列表混合?

Python 在列表列表中,如何确保一个列表中的列表元素不会与其他列表混合?,python,list,nested-lists,Python,List,Nested Lists,我有一个可以检索电视节目列表的应用程序。此列表是程序对象的列表。在我的代码中,检索此列表的方法通过电视频道列表进行迭代,称为get\u programs() 所以问题是,当我在programs\u all列表中循环时,我没有得到一致的顺序。A频道和B频道的节目有时会混在一起 print(len(programs_all)) # This should give 2 to show that we have a list of 2 lists for prog in programs_all:

我有一个可以检索电视节目列表的应用程序。此列表是程序对象的列表。在我的代码中,检索此列表的方法通过电视频道列表进行迭代,称为
get\u programs()

所以问题是,当我在
programs\u all
列表中循环时,我没有得到一致的顺序。A频道和B频道的节目有时会混在一起

print(len(programs_all)) # This should give 2 to show that we have a list of 2 lists

for prog in programs_all:
    print("Start of list")
    for p in prog:
       print(p.channel) # Accessing an attribute in Program object
    print("End of list")
输出-一些B通道程序在A通道程序之间打印

2
Start of list
A
A
A
A
A
A
B
B
A
B
A
End of list
Start of list
B
B
B
B
B
B
B
End of list
我如何确保列表结构正确,以便始终获得以下预期输出:

2
Start of list
A
A
A
A
A
A
A
A
A
End of list
Start of list
B
B
B
B
B
B
B
B
End of list

Ps:请忽略元素计数,因为它们在这个任务中只是随机的。

这很可能是
get\u programs()
函数的逻辑中的一个问题,没有它,就无法诊断问题。请提供一个包含足够的可运行代码以重现您的问题。您好,Craig,
get_programs()
正在使用一个电视指南网站公开的web服务。返回一个频道的完整列表需要几分钟的时间。您是否认为这与列表结构不正确有关,因为对B频道的第二次呼叫是在对A频道的第一次呼叫仍在进行时完成的?我将尝试在几天内提供一个最小的代码。
2
Start of list
A
A
A
A
A
A
A
A
A
End of list
Start of list
B
B
B
B
B
B
B
B
End of list