Sujet : Two aces up Python's sleeve
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.pythonDate : 06. Nov 2024, 01:49:15
Autres entêtes
Organisation : Stefan Ram
Message-ID : <seven-20241106014329@ram.dialup.fu-berlin.de>
ram@zedat.fu-berlin.de (Stefan Ram) wrote or quoted:
last_item = my_list[ -1 ]
Way cleaner than my_list[ len( my_list )- 1 ], don't you think?
In "The Mental Game of Python," Raymond Hettinger spills the
beans about our noggins only being able to juggle 7 +/- 2
things in our short-term memory.
So, "last_item = my_list[ -1 ]" might still make the cut,
while "my_list[ len( my_list)- 1 ]" could be biting off
more than we can chew.
|The problem is, the number of brain registers this uses is
|10. This is no longer a decryption effort. This is a puzzle.
|At the moment you put it together, you fully understand it.
|But if this is embedded in bigger code, every time you hit
|this line, you're going to have to pick apart "what does this
|thing do?".
Raymond Hettinger