[Tutor] this group and one liners

Albert-Jan Roskam sjeik_appie at hotmail.com
Thu Jul 7 10:19:44 EDT 2022


   On Jul 6, 2022 17:50, avi.e.gross at gmail.com 

     As has often been discussed, quite a bit is done in languages like
     python using constructs like:

     [ x+2 for x in iterator ]

   ======
   My rule of thumb is: if black converts a list/set/dict comprehension into
   a multiline expression, I'll probably refactor it. I try to avoid nested
   loops in them. Nested comprehensions may be ok. Nested ternary expressions
   are ugly, even more so inside comprehensions!

     Specifically with some of the code I shared recently, I pointed out that
     if max() failed for empty lists as an argument, you could simply create
     a safe_max() function of your own that encapsulates one of several
     variations and returns a 0 when you pass it something without a maximum.

   ====
   Or this?
   max(items or [0])


More information about the Tutor mailing list