0

How this function works?

x.count(x[0]) == len(x) It's used to check if the item in the list are identical.. But i can't figure out how it's actually working..

8th Jul 2019, 9:27 AM
Amit Dubey
Amit Dubey - avatar
5 Respostas
+ 2
Depends what you meant with "identical", here is an example, where items have the same value, but different datatype. [0, False, 0.0, 0j].count(0) And it would return 4.
8th Jul 2019, 9:36 AM
Seb TheS
Seb TheS - avatar
+ 1
x.count([1, 1, 1])
8th Jul 2019, 9:42 AM
Seb TheS
Seb TheS - avatar
+ 1
Thank you!
8th Jul 2019, 9:44 AM
Amit Dubey
Amit Dubey - avatar
0
x = [[1, 1, 1], [0,2, 0], [1, 2, 0]] How about this example..can you tell me how it will or work on this
8th Jul 2019, 9:39 AM
Amit Dubey
Amit Dubey - avatar
0
I got it..
8th Jul 2019, 9:43 AM
Amit Dubey
Amit Dubey - avatar