0
Output not understood!
How and why is the output? https://code.sololearn.com/cvYjTW18i55q/?ref=app
6 Respuestas
+ 7
because ([]) is same as [] (empty list == False)
but [()] is True as not empty list (contains an empty tuple)...
tuple containing a list must be written: ([],) to explicitly mark parenthesis as a tuple with only one item (else parenthesis are evaluated as mathematical expression ^^)
+ 3
I believe it's because in: [([]), [()]]
the value at the first index is: ([])
*** the parenthesis are treated as parenthesis NOT tuple
SO, the correct first index value is: [] (an empty list)
the second value is: [()] (a list w/ an empty tuple inside)
When checking bools, anything 0, None, or empty iterables are considered False. Any value is True.
So you get:
False
True
+ 2
Slick not every time: don't believe that :D
+ 2
For illustration you may output item and type:
l=[([]),[()], (), (1), (1,), []]
for i in l:
print(i, type(i), bool(i), sep=" ")
+ 1
visph dang bro, so much faster than me every time
+ 1
RuntimeERROR in fact, parenthesis always are treated as mathematical expression... and tuple require to be parenthesis only in some cases:
t = a, b
create a tuple...
also:
t = a,
but as list item, parenthesis are required to explicitly mark the tuple boundaries from list items boundaries (wich too use comma as separator) ;)