[#]TIL to use a dict-comprehension in an f-string add parens or whitespace #Python
d = {'a': 1, 'b': 2, 'c': 3, 'd': 5, 'e': 6}
f"{({k: v for k, v in d.items() if v % 2})}"
"{'a': 1, 'c': 3, 'd': 5}"
f"{ {k: v for k, v in d.items() if v % 2} }"
"{'a': 1, 'c': 3, 'd': 5}"
=> More informations about this toot | View the thread | More toots from alex@moreati.org.uk
=> View til tag | View python tag This content has been proxied by September (3851b).Proxy Information
text/gemini