python - pythonic way of handling nested for loop -
i have following code , sake of learning see more pythonic way of achieving this:
for value in response.values(): encod in encodings: if encod.lower() in value.lower(): return(encod)
if you're looking different way, can use this:
return next(encod value in response.values() encod in encodings if encod.lower() in value.lower())
the portion within next(...)
generator expression yields each encod
in encodings
for each value
in response.values()
if condition encod.lower() in value.lower()
satisfied. first element of generator return (see next()
).
although, in practice, go have. it's simplest , clearest way trying do, , no means unpythonic.
Comments
Post a Comment