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

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -