re: What are your favorite programming language syntax features? VIEW POST


List Comprehensions in Python is an interesting one. I absolutely love them in some cases, and despise them on others.

# Simple and elegant...
squares = [n**2 for n in numbers]

list_a = [...]
list_b = [...]
# ...not on this one IMO, I'd prefer loops instead.
different_num = [(a, b) for a in list_a for b in list_b if a != b]

It's my first time to see such syntax since I haven't really touched Python. Looks interesting , I couldn't understand what the last line does though.


The last line is:

for a in list_a:
    for b in list_b:
        if a != b:
            different_num.append((a, b))
Code of Conduct Report abuse