I just randomly observed the following in Python and am curious to know the reason why this evaluates to False
:
list(list()) == [[]]
Interestingly if you rearrange the syntax in the following ways, the first way evaluates as False
, but the second as True
:
list([]) == [[]]
[list()] == [[]]
What is going on under the hood here?
List allows duplicates while Set doesn't allow duplicate elements . All the elements of a Set should be unique if you try to insert the duplicate element in Set it would replace the existing value. List permits any number of null values in its collection while Set permits only one null value in its collection.
Duplicates : ArrayList allows duplicate values while HashSet doesn't allow duplicates values.
list
does not construct a list that contains its argument; it constructs a list whose elements are contained in its argument. list([])
does not return [[]]
; it returns []
. Thus, list(list()) == list([]) == []
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With