Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write better code instead of 2 for loops

I have 2 for loops and I want to make it better like list comprehension or lambda or else. how can i achieve the same?

for example :

filename = ['a.txt', 'b.txt', 'c.txt']
for files in filename:
    for f in glob.glob(os.path.join(source_path, files)):
        print f
        ... some processing...
like image 403
sam Avatar asked Apr 14 '12 07:04

sam


People also ask

Can there be more than 2 loops in a program?

The outer loop can contain more than one inner loop. There is no limitation on the chaining of loops.


1 Answers

Your code is perfectly fine as it is. You can only make it less legible by introducing unnecessary complex constructs.

like image 187
thebjorn Avatar answered Sep 22 '22 04:09

thebjorn