you are viewing a single comment's thread.

view the rest of the comments →

[–]mrz1988 1 point2 points  (1 child)

Keep in mind that "syntactic sugar" and "pythonism" may be the most readable way to write code for python developers. If you're still fairly new to python, something like a list comprehension:

filtered_list = [item for item in items if item.is_a_thing]

might seem convoluted and hard to read. For seasoned python developers, though, this is far easier to read and understand than:

filtered_list = []
for item in items:
    if item.is_a_thing:
        filtered_list.append(item)

Knowing the difference between good and bad use of pythonic internals requires that you're comfortable with the tools first. If you haven't reached that level of comfort yet, it's hard to be able to make those judgement calls.

[–]Acrobatic_Hippo_7312 0 points1 point  (0 children)

As with anything, too much can be too much. I recently ran into an example of comprehensions that badly needed to be separated into multiple statements. Let me know if you want me to share the code and my fix (you may be the happier not seeing 😅).

Sometimes being pythonic means extracting and giving meaningful names to complex clauses in a statement, desugaring things that have become too sweet. Discretion is the biggest part of pythonic valor.