How to map each sublist to its ordinal number preserving the original lengths in Python

1 Answer

0 votes
lst = [[4, 6, 2], [9, 0, 12, 736], [40], [-7, 32], [90]]

lst = [[idx] * len(sublist) for idx, sublist in enumerate(lst)]

print(lst)


'''
run:
 
[[0, 0, 0], [1, 1, 1, 1], [2], [3, 3], [4]]
 
'''

 



answered Feb 14 by avibootz
...