在列表中查找元素

时间:2020-06-03 10:57:30

标签: python list

var ldap = require('ldapjs');
var client = ldap.createClient({
  url: 'ldap://127.0.0.1:1389'
});

client.bind('cn=root', 'secret', function(err) {
  if(err){console.log(err);}
});

给我:

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])

如何处理第二行[(1, 2, 3, 4), (1, 2, 4, 3), ... ] (1, 2, 3, 4) 中的数字?

我必须解决括号中的每个数字并加以处理。

(1, 2, 3, 4)不起作用。

谢谢。

1 个答案:

答案 0 :(得分:0)

要在第一个结果中使用每个数字,可以使用for循环。

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

或者如果您想对所有结果都这样做:

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