Answers for "how to split list into sublists python"

1

split list into list of lists python on every n element

big_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
x = 4
list_of_lists = [big_list[i:i+x] for i in range(0, len(big_list), x)]
# [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
Posted by: Guest on September-10-2020
8

split list into lists of equal length python

[lst[i:i + n] for i in range(0, len(lst), n)]
Posted by: Guest on March-31-2020
1

python split list into n sublists

[input[i:i+n] for i in range(0, len(input), n)]        # Use xrange in py2k
Posted by: Guest on July-19-2021

Code answers related to "how to split list into sublists python"

Python Answers by Framework

Browse Popular Code Answers by Language