Python: List Comprehensions
If I'd like to create a list based on the existing objects (maybe a list or a sequence of numbers), it's a good way to achieve the goal. I often use this to build a list of files. For example,
The program will generate four files named output_6, output_7, output_8, and output_9.
Reference:
http://www.swaroopch.com/notes/python/#list_comprehension
output = [open('output_%s' %(i), 'w+') for i in range(6, 10, 1)]
The program will generate four files named output_6, output_7, output_8, and output_9.
Reference:
http://www.swaroopch.com/notes/python/#list_comprehension
留言
張貼留言