Lum*_*ath 2 python iteration nested-lists
如果我有一个如下所示的嵌套列表:
bigstringlist = [['rob', 'bob', 'sam', 'angie'], ['jim', 'angie', 'tom', 'sam'], ['sam', 'mary', 'angie', 'sally']]
如何遍历此列表并提取出现在所有嵌套列表中的名称列表?即:
finallist = ['sam', 'angie']
Run Code Online (Sandbox Code Playgroud)
将这个嵌套列表作为一个集合进行类型转换可以更好地完成吗?
mou*_*uad 11
reduce(set.intersection, map(set , bigstringlist))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
587 次 |
| 最近记录: |