That’s not a list. You are using a dictionary with key and value. Get the value, split
on comma and find length using len
.
workdays = {'work': '5,6,8,10,13,14,15,18,20,22,24,25,28,30'}
print('I have worked {} days'.format(len(workdays['work'].split(','))))
Also, you could count the number of commas and add 1
to it to get the same result like so:
print('I have worked {} days'.format(workdays['work'].count(',')+1))
solved count total in a list python by split