[os.path.join(r'E:\Python', name) for name in []] returns []

Dave Angel davea at davea.name
Tue Jan 29 14:36:21 CET 2013

On 01/29/2013 08:21 AM, iMath wrote:
> why [os.path.join(r'E:\Python', name) for name in []] returns [] ?
> please explain it in detail !

[ os.path.join(r'E:\Python', name) for name in [] ]

It'd be nice if you would explain what part of it bothers you.  Do you 
know what a list comprehension is?  Do you know how to decompose a list 
comprehension into a for-loop?  Do you know that [] is an empty list object?

res = []
for name in []:
     res.append( XXXX )

Since the for loop doesn't loop even once, the result is the initial 
value, the empty loop.


More information about the Python-list mailing list