Created
June 29, 2011 20:11
-
-
Save chooper/1054819 to your computer and use it in GitHub Desktop.
Merging list of lists in Python using reduce()
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
#!/usr/bin/env python | |
"""Merging list of lists in Python using reduce()""" | |
def merge_lists(list_of_lists): | |
return reduce(lambda x,y: x+y, list_of_lists) | |
if __name__ == '__main__': | |
my_big_list = [ [1,2,3], [3,4,5], [6,7,8], ] | |
print merge_lists(my_big_list) | |
# output: [1, 2, 3, 3, 4, 5, 6, 7, 8] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tested this code in a large list data , waited a long time, but no result were returned. i used following funtion, and i got the result very quickly. i don't know why.
new_list=[]
for i in my_big_list :
new_list.extend(i)