Answers for "how to split list into 2 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
0

split list in 3 part

def even_divide(lst, num_piece=4):
    return [
        [lst[i] for i in range(len(lst)) if (i % num_piece) == r]
        for r in range(num_piece)
    ]
Posted by: Guest on May-02-2020

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

Python Answers by Framework

Browse Popular Code Answers by Language