hapaxlegomina@artemis.camp 1 year ago
Don’t forget Python’s amazing list comprehension syntax!
guess = input(“Guess a letter:”).lower()
display = [ letter if letter == guess else “_” for letter in word ]
Just one part of your question, but it saves a lot of futzing around with indices and replace
s.
Turun@feddit.de 1 year ago
Even as an experienced python dev I sometimes prefer explicit for loops over list comprehensions. I think for people who didn’t even grasp the concept of a for loop they are more confusing than helping.
falsem@kbin.social 1 year ago
Yeah, I'm not a fan of them overall. I think multiple lines is more readable. There are a LOT of people that disagree with me though.
mo_ztt@lemmy.world 1 year ago
I thought I was the only one… to me unless it’s a super-simplistic comprehension, it has a similar effect as when C programmers write
if (xx = !(1 == (a ? !c : 34 ^ blit_target))) {
. Congratulations, you fit it all on one line! At the expense of totally destroying my train of thought when I’m trying to scan down the code and figure out what the hell’s going on. Well done.