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...
The outer loop can contain more than one inner loop. There is no limitation on the chaining of loops.
Your code is perfectly fine as it is. You can only make it less legible by introducing unnecessary complex constructs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With