a=['Миша', '5', '55', '120', 'Хуан', '0', '4', 'Ваня', '6', '4', '1', 'Педро', '2.35', '3.40']
n = 4
f=list(zip(*[iter(a)]*n))
print(f)
[('Миша', '5', '55', '120'), ('Хуан', '0', '4', 'Ваня'), ('6', '4', '1', 'Педро')]
[('Миша', '5', '55', '120'), ('Хуан', '0', '4'), ('Ваня', '6', '4', '1'), ('Педро', '2.35', '3.40')]
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys,re
def main(argv=sys.argv):
a = ['Миша', '5', '55', '120', 'Хуан', '0', '4', 'Ваня', '6', '4', '1', 'Педро', '2.35', '3.40']
ss = list()
ss1 = list()
for i in a:
if not re.search(r"\d",str(i)):
if ss1:
ss.append(tuple(ss1))
ss1 = list()
ss1.append(i)
else:
ss1.append(i)
ss.append(tuple(ss1))
print(ss)
if __name__ == "__main__":
sys.exit(main())
def test(a):
start = 0
result = []
for i, item in enumerate(a[1:]):
if not item.replace('.', '', 1).isdigit(): # to handle float
end = i
result.append(a[start:end + 1])
start = end + 1
result.append(a[start:])
return result
res = []
temp=[]
for w in a:
if w[0].isalpha():
if temp:
res.append(temp)
temp = []
temp.append(w)
res.append(temp)
print(res)
idx = [i for i, x in enumerate(a) if x[0].isalpha()]
res = [a[i:j] for i,j in zip(idx, idx[1:]+[len(a)])]
print(res)