This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年09月02日 16:25 by varun_masuraha, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (5) | |||
|---|---|---|---|
| msg169707 - (view) | Author: Varun Masuraha (varun_masuraha) | Date: 2012年09月02日 16:25 | |
setup: >>>myList=[1,True,'blah blah'] >>>print(myList.count(1)) Actual result: 2 Expected: 1 |
|||
| msg169708 - (view) | Author: Alex Gaynor (alex) * (Python committer) | Date: 2012年09月02日 16:30 | |
list.count() uses == to compare items, 1 and True compare equal, so this behavior is correct. |
|||
| msg169716 - (view) | Author: Varun Masuraha (varun_masuraha) | Date: 2012年09月02日 18:23 | |
Thanks Alex for the reply, Although Booleans & Integers may not be very practical in same list (or tuple, etc.) & the fact that bool is subclass of int, still I feel that the search implementation (count, index, etc.) is too simple in that matter. Comparing both Value AND Data type while searching, looks more exact to me... regards, Varun |
|||
| msg169747 - (view) | Author: Martin v. Löwis (loewis) * (Python committer) | Date: 2012年09月03日 05:51 | |
Varun: what do you think that py> x = [1.0, 2.0, 3.0] py> x.count(3) 1 should give? I think most people will agree that there is one single "three" in the list, as 3 and 3.0 are equal in all other contexts as well (as is 3.0+0j). If types were considered, this would give 0. |
|||
| msg169751 - (view) | Author: Varun Masuraha (varun_masuraha) | Date: 2012年09月03日 08:46 | |
Hey Martin, I think I got the point. Meanwhile I created my own myCount() for my problem ;-) Thanks. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:35 | admin | set | github: 60054 |
| 2012年09月03日 08:46:25 | varun_masuraha | set | messages: + msg169751 |
| 2012年09月03日 05:51:03 | loewis | set | nosy:
+ loewis messages: + msg169747 |
| 2012年09月02日 18:23:43 | varun_masuraha | set | messages: + msg169716 |
| 2012年09月02日 16:30:43 | alex | set | status: open -> closed nosy: + alex messages: + msg169708 resolution: not a bug |
| 2012年09月02日 16:25:55 | varun_masuraha | create | |