+ 1
Length function in python
a = ([{}]) print (len(a)) #outputs 1. Can somebody explain why it is so???
1 Respuesta
+ 15
{} is an element of the list
[ { } ] ---> a list with an empty dictionary as its element.
So even if the dictionary is empty, we are counting the number of elements of the list and not the dictionary inside it.
Another Example:
a = [ { }, { } ]
print(len(a))
>> 2