Reputation: 1
I am new to python and I need to take a list populated with numerical values and create a sublist containing specific values from that list.
The original list contains 16,419 individual numerical values. I need to make multiple lists from this original that contain 4500 values each.
Sample code (pretend the length of 'Original_List' is 16419):
Original_List = [46325, 54326, 32666, 32453, 54325, 32542, 38573]
First_4500_Numbers = []
First_4500_Numbers.append(List_of_16419_Indivudual_Numbers[0:4499])
The above code is creating a list that looks like this:
print(First_4500_Numbers)
[[46325, 54326, 32666, 32453, 54325, 32542, 38573]]
How can I get rid of this extra bracket on the outside of the list? It is causing downstream issues.
Thank you for any help!
Upvotes: 0
Views: 46
Reputation: 1580
List_of_16419_Indivudual_Numbers[0:4499]
returns a list. You don't need to append it to another one. Try just this:
Original_List = [46325, 54326, 32666, 32453, 54325, 32542, 38573]
First_4500_Numbers = Original_List[0:4499]
Then output will look like
>>> print(First_4500_Numbers)
[46325, 54326, 32666, 32453, 54325, 32542, 38573]
Upvotes: 4