简体   繁体   English

在列表中查找元素

[英]Find elements in list

from itertools import permutations as pm

perm = pm([1, 2, 3, 4])
pm_list = []

for i in list(perm):
    pm_list.append(i)

print(pm_list)
print(pm_list[0])

gives me:给我:

[(1, 2, 3, 4), (1, 2, 4, 3), ... ]
(1, 2, 3, 4)

How can I work with the numbers in the second row (1, 2, 3, 4) ?如何处理第二行(1, 2, 3, 4)中的数字?

I have to address and to work with every single number in the bracket.我必须解决并处理括号中的每个数字。

print(pm_list[0][0]) doesn't work. print(pm_list[0][0])不起作用。

Thanks in advance.提前致谢。

To use every number in the first result you can use a for loop.要使用第一个结果中的每个数字,您可以使用 for 循环。

for number in pm_list[0]:
   print (number)

Or if you want to do this for all results:或者,如果您想对所有结果执行此操作:

for result in pm_list:
   for number in result:
       print (number)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM