-
-
Notifications
You must be signed in to change notification settings - Fork 5
PythonHintsForNoobs
Anthony Sottile edited this page Aug 18, 2020
·
4 revisions
-
dict(python<3.6) andsetare unordered types, This means iterating them, their keys, or their values is not well defined -
listandtupleare ordered types. Iterating them is well defined -
tupleis immutable, it cannot be modified. If you want a mutable thing, use alistordeque
derpy
if foo == 'bar':
return True
else:
return False
return True if foo == 'bar' else Falsenot derpy
return foo == 'bar'dict(...).copy() is a redundant shallow copy, write dict(...) instead
derpy
[f(x) for x in dct.keys()]
y in dct.keys()
set(dct.keys())not derpy
[f(x) for x in dct]
y in dct
set(dct)