how to calculate number of values appeared in a string of list of lists
a=['1000','10,8,6','9,76,9.0','1,2']
required output
b=[1,3,3,2]
a is in my input, the required output is b how to do it using python
CodePudding user response:
You can use str.split()
then with len(list)
get what you want.
Try this:
>>> '10,8,6'.split(',')
['10', '8', '6']
>>> len(['10', '8', '6'])
3
>>> a=['1000','10,8,6','9,76,9.0','1,2']
>>> [len(s.split(',')) for s in a]
[1,3,3,2]