If I have a nested list that looks like this:
bigstringlist = [['rob', 'bob', 'sam', 'angie'], ['jim', 'angie', 'tom', 'sam'], ['sam', 'mary', 'angie', 'sally']]
How do I iterate through this list and extract a list of names that appear in all the nest开发者_如何学JAVAed lists? i.e.:
finallist = ['sam', 'angie']
Would this be better accomplished by typecasting this nested list as a set?
reduce(set.intersection, map(set , bigstringlist))
A variation on singularity's solution, maybe a little faster:
bigstringiter = iter(bigstringlist)
reduce(set.intersection, bigstringiter, set(next(bigstringiter)))
精彩评论