简体   繁体   中英

What's the most efficient way of intersecting to collections in Python?

I'm new in python, sorry if there's anything wrong.

I'd like to intersect several collections (20 o 30) with a big amount of elements in them.

I've been reading and know that Sets are similar to hashtables (work with the same principle). Sets has the intersect method, i've been trying it and works really fine.

But, would like to have an experienced opinion.

What would you do?

The problem again. 20 or 30 collections (can be set, the elements are not repeated) and want to make intersection of them. Don't think how the collections are created (ie the insertion doesn't matters)

Thanks a lot!

result = set1.intersection(set2, set3, set4, ...)

http://docs.python.org/library/stdtypes.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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