1
0
mirror of https://github.com/satwikkansal/wtfpython synced 2024-11-22 11:04:25 +01:00

Update exmaple: Counting the booleans

* Changes name to "What's wrong with booleans"
* Add another snippet to the example.
This commit is contained in:
Satwik Kansal 2017-09-04 23:16:31 +05:30
parent ad6898e6f4
commit 8216f02618

33
README.md vendored
View File

@ -81,14 +81,16 @@ So, here ya go...
- [💡 Explanation](#-explanation-10) - [💡 Explanation](#-explanation-10)
- [Midnight time doesn't exist?](#midnight-time-doesnt-exist) - [Midnight time doesn't exist?](#midnight-time-doesnt-exist)
- [💡 Explanation:](#-explanation-18) - [💡 Explanation:](#-explanation-18)
- [Counting the booleans](#counting-the-booleans) - [What's wrong with booleans?](#whats-wrong-with-booleans)
- [💡 Explanation:](#-explanation-19) - [💡 Explanation:](#-explanation-19)
- [Needle in a Haystack](#needle-in-a-haystack) - [Needle in a Haystack](#needle-in-a-haystack)
- [💡 Explanation:](#-explanation-20) - [💡 Explanation:](#-explanation-20)
- [Loop variable resilient to changes](#loop-variable-resilient-to-changes) - [not knot!](#not-knot)
- [💡 Explanation:](#-explanation-21) - [💡 Explanation:](#-explanation-21)
- [Let's see if you can guess this?](#lets-see-if-you-can-guess-this) - [Loop variable resilient to changes](#loop-variable-resilient-to-changes)
- [💡 Explanation:](#-explanation-22) - [💡 Explanation:](#-explanation-22)
- [Let's see if you can guess this?](#lets-see-if-you-can-guess-this)
- [💡 Explanation:](#-explanation-23)
- [Minor Ones](#minor-ones) - [Minor Ones](#minor-ones)
- [TODO: Hell of an example!](#todo-hell-of-an-example) - [TODO: Hell of an example!](#todo-hell-of-an-example)
- [Contributing](#contributing) - [Contributing](#contributing)
@ -220,6 +222,7 @@ Shouldn't that be 100?
### Time for some hash brownies! ### Time for some hash brownies!
1\.
```py ```py
some_dict = {} some_dict = {}
some_dict[5.5] = "Ruby" some_dict[5.5] = "Ruby"
@ -1379,8 +1382,9 @@ Before Python 3.5, the boolean value for `datetime.time` object was considered t
--- ---
### Counting the booleans ### What's wrong with booleans?
1\.
```py ```py
# A simple example to count the number of boolean and # A simple example to count the number of boolean and
# integers in an iterable of mixed data types. # integers in an iterable of mixed data types.
@ -1403,6 +1407,21 @@ for item in mixed_list:
4 4
``` ```
2\.
```py
another_dict = {}
another_dict[True] = "JavaScript"
another_dict[1] = "Ruby"
another_dict[1.0] = "Python"
```
**Output:**
```py
>>> another_dict[True]
"Python"
```
#### 💡 Explanation: #### 💡 Explanation:
* Booleans are a subclass of `int` * Booleans are a subclass of `int`
@ -1413,6 +1432,12 @@ for item in mixed_list:
True True
``` ```
* The integer value of `True` is `1` and that of `False` is `0`.
```py
>>> True == 1 == 1.0 and False == 0 == 0.0
True
```
* See this StackOverflow [answer](https://stackoverflow.com/a/8169049/4354153) for rationale behind it. * See this StackOverflow [answer](https://stackoverflow.com/a/8169049/4354153) for rationale behind it.
--- ---