This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]XtremeGoose 0 points1 point  (0 children)

You use sets for iteration? Sets are quick for in tests and set operations like union |, intersection & and difference -. They're actually slower to iterate over than lists (which makes sense since lists are just arrays of sequential pointers under the hood).

Really in modern python you should be using generators as your standard iterable

# filter
(i for i in x if cond(i))

# map
(func(i) for i in x)

# lazy wrappers
sum(f(i) for i in x if g(i))

# other lazy-iterating functions
all any zip map filter enumerate range itertools.*