I have a list of unequal lists. I would like to create a new list with an understanding of the list of subscriptions.
s = [['a','b','c','d'],['e','f','g'],['h','i'],['j','k','l','m']]
I try to use the following code, it keeps raising indexError
new_s = [] for i in range(len(s)): new_s.append((i,[t[i] for t in s if t[i]))
Expected Result:
new_s = [(0,['a','e','h','j']),(1,['b','f','i','k']),(2,['c','g','l']),(3,['d','m'])]
Any ideas how to make this work?
python
Jadox
source share