I have a list of dictionary:
>>> Fruits = [{'apple': 'red', 'orange': 'orange'}, {'pear': 'green', 'cherry': 'red', 'lemon': 'yellow'}, {}, {}]
>>>
>>> len (Fruits)
4
List 0: {'orange': 'orange', 'apple': 'red'}
List 1: {'cherry': 'red', 'lemon': 'yellow', 'pear': 'green'}
List 2: {}
List 3: {}
Although len (Fruits) does return the "correct" length, I'm wondering if there's a shortcut command only return the length of the list that has values in them?
Ultimately, I wanted to do:
# Length Fruits is expected to be 2 instead of 4.
for i in range (len (Fruits)):
# Do something with Fruits
Fruits [i]['grapes'] = 'purple'