- 1
Hello everyone, please, tell me how I can divide this array into 3 arrays
INPUT: ['name', 'surname', '01.01.1970', 'departament', 15000, '', 'name2', 'surname2', '01.01.1970', 'departament', 15000, '', 'name3', 'surname3', '01.01.1970', 'departament', 15000, ''] OUTPUT: ['name', 'surname', '01.01.1970', 'departament', 15000] ['name2', 'surname2', '01.01.1970', 'departament', 15000] ['name3', 'surname3', '01.01.1970', 'departament', 15000]
2 Réponses
+ 1
I am using list comprehension ,
arr= ['name', 'surname', '01.01.1970', 'departament', 15000, '', 'name2', 'surname2', '01.01.1970', 'departament', 15000, '', 'name3', 'surname3', '01.01.1970', 'departament', 15000, '']
print(*(arr[i:i+5] for i in range(int(len(arr)/5))))
0
Abhay, thank you