Jun-07-2019, 06:36 PM
inv = { 'cash': ['gold', 'gold'], } print(inv['cash']) print(' '.join(inv['cash'])) print(' '.count(inv['cash']))I can print the 'cash' list.
I can print the 'cash' list with the brackets and quotations stripped off.
If I try to count the number of items in the 'cash' list, Python gets angry.
How do I count the number of items in the 'cash' list? I just want it to return a number. Can this be done in one line using indexing syntax?
I've been reading tutorials online that show how to count items in nested lists and they are huge monstrosities. There has to be a simple way to do it. I'm surprised my third print statement doesn't work. It says it wants it to be a string, not a list. Trying to convert it to a string:
print(' '.count(str(inv['cash'])))
returns 0 when it should return 2.
Any help would be appreciated.