I've got a raw text file with a line-separated list of EAN numbers, which I'm adding to a list (as a string) as follows:
listofEAN = []
with open('Data', newline='\r\n') as inputfile:
for row in csv.reader(inputfile):
listofEAN.append(row)
This creates a "list of lists" (I'm not sure why it doesn't create a single list?) in the format:
[['0075678660924'], ['0093624912613'], ['3299039990322'], ['0190295790394'], ['0075678660627'], ['0075678661150'], ...]
I'm trying to do transform the list into a list of lists with 10 EAN's each. So running listofEAN[0]
would return the first 10 EAN's, and so forth.
I'm afraid I'm struggling to do this - I presume I need to use a loop of some kind, but I'm having trouble with creating a loop and combining the loop operations with the list syntax.
Any pointers would be greatly appreciated.
EDIT: Similar to the query here: How do you split a list into evenly sized chunks? but the corrections here to the way I'm importing the list is of particular interest. Thank you!