tl-semicolon-dr

tl;dr for various ressource I read, heard or saw

View the Project on GitHub knil-sama/tl-semicolon-dr

Source

PEP 572 Assignment Expression

tl;dr

# Compute partial sums in a list comprehension
total = 0
partial_sums = [total := total + v for v in values]
print("Total:", total)
if any((comment := line).startswith('#') for line in lines):
    print("First comment:", comment)
else:
    print("There are no comments")

if all((nonblank := line).strip() == '' for line in lines):
    print("All lines are blank")
else:
    print("First non-blank line:", nonblank)
# Loop-and-a-half
while (command := input("> ")) != "quit":
    print("You entered:", command)

Afterword

Already feel the need for this feature while coding some big comprehension list and can’t wait to use is in 3.8.