How to split the elements of a list into a list of lists in Python

1 Answer

0 votes
lst = ['python-1', 'c-2', 'c++-3', 'java-4', 'nodejs-5']
 
result = [item.split('-') for item in lst]
 
print(result) 
 
 
 
 
'''
run:
 
[['python', '1'], ['c', '2'], ['c++', '3'], ['java', '4'], ['nodejs', '5']]

'''

 



answered Jul 26, 2022 by avibootz
...