Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python repeat set generator

Is there a simpler way of doing the following?

(set() for _ in itertools.repeat(None))

Note that it is different to itertools.repeat(set()), since the latter only constructs the set object once.

like image 466
simonzack Avatar asked Aug 22 '14 07:08

simonzack


1 Answers

You can do

iter(set, None)

which calls the given callable until it returns None (what it won't).

like image 90
glglgl Avatar answered Oct 12 '22 22:10

glglgl