Created
March 13, 2015 15:57
-
-
Save etheriqa/5723fcab1584412b2ca8 to your computer and use it in GitHub Desktop.
mapM and mapM_ in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# open 0.txt, 2.txt, ..., 9.txt | |
# list comprehension | |
fs = [open('{0}.txt'.format(i)) for i in range(10)] | |
[f.close() for f in fs] | |
# map | |
fs = map(lambda i: open('{0}.txt'.format(i)), range(10)) | |
map(lambda f: f.close(), fs) | |
# for loop | |
fs = [] | |
for i in range(10): | |
fs.append(open('{0}.txt'.format(i))) | |
for f in fs: | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment