Home > Software engineering >  How do i section a list by dividing it into more lists in python?
How do i section a list by dividing it into more lists in python?

Time:10-14

Ok so i have a list in python, for example:

[['02357413'], [30], ['02357413'], [22], ['02357185'], [23], ['02357185'], [24]]

And i want to convert it into this:

[['02357413', 30], ['02357413', 22], ['02357185', 23], ['02357185', 24]]

Thank you in advance

CodePudding user response:

You can use list comprehension in Python to do so as follow:

>>> a = [['02357413'], [30], ['02357413'], [22], ['02357185'], [23], ['02357185'], [24]]
>>> [a[i] a[i 1] for i in range(0,len(a)-1, 2)]
[['02357413', 30], ['02357413', 22], ['02357185', 23], ['02357185', 24]]
>>>
  • Related