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

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

java - SmsManager sending message more than one -