On Thu, 13 Jan 2005 17:05:39 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote: > > "Stephen Thorne" <[EMAIL PROTECTED]> ÑÐÐÐÑÐÐ/ÑÐÐÐÑÐÐÐ Ð > ÐÐÐÐÑÑÑÑ > ÑÐÐÐÑÑÑÐÐ: news:[EMAIL PROTECTED] > On Thu, 13 Jan 2005 15:55:10 +1000, Egor Bolonev <[EMAIL PROTECTED]> wrote: > > how to get rid of 'for' operator in the code? > > > > import os, os.path > > > > def _test(): > > src = 'C:\\Documents and Settings\\ÐÐÐÑ\\My Documents\\My Music\\' > > > > for i in [x for x in os.listdir(src) if > > os.path.isfile(os.path.join(src, > > x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u']: > > os.remove(os.path.join(src, i)) > > > > if __name__ == '__main__': > > _test() > > import glob > for x in glob.glob("*.m3u"): > os.remove(x) > > i want to wipe out 'for x in []: f(x)' using map, lambda, reduce, filter and > List > Comprehensions [x for x in []] > just don't get how to add string to all elements of list
Here's a few ways, map(os.remove, glob.glob("*.m3u")) [os.remove(x) for x in glob.glob("*.m3u")] [os.remove(x) for x in os.listdir(src) if os.path.isfile(os.path.join(src, x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u'] def myfilter(x): return os.path.isfile(os.path.join(src, x)) and len(x.split('.')) > 1 and x.split('.')[-1].lower() == 'm3u' map(os.remove, filter(myfilter, os.listdir(src))) Regards, Stephen Thorne. -- http://mail.python.org/mailman/listinfo/python-list