Set Comprehensions

Similarly to list comprehensions, set comprehensions are also supported:

>>> a = {x for x in 'abracadabra' if x not in 'abc'}
>>> a
set(['r', 'd'])

Syntax

{expr for iter_var in iterable}
{expr for iter_var in iterable if cond_expr}

References

[1] [email protected] Developer's Guide, PEP 218 -- Adding a Built-In Set Object Type

[2] [email protected], 5. Data Structures — 5.4. Sets

results matching ""

    No results matching ""