Skip to content

Commit 8216f02

Browse files
committed
Update exmaple: Counting the booleans
* Changes name to "What's wrong with booleans" * Add another snippet to the example.
1 parent ad6898e commit 8216f02

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,16 @@ So, here ya go...
8181
- [💡 Explanation](#-explanation-10)
8282
- [Midnight time doesn't exist?](#midnight-time-doesnt-exist)
8383
- [💡 Explanation:](#-explanation-18)
84-
- [Counting the booleans](#counting-the-booleans)
84+
- [What's wrong with booleans?](#whats-wrong-with-booleans)
8585
- [💡 Explanation:](#-explanation-19)
8686
- [Needle in a Haystack](#needle-in-a-haystack)
8787
- [💡 Explanation:](#-explanation-20)
88-
- [Loop variable resilient to changes](#loop-variable-resilient-to-changes)
88+
- [not knot!](#not-knot)
8989
- [💡 Explanation:](#-explanation-21)
90-
- [Let's see if you can guess this?](#lets-see-if-you-can-guess-this)
90+
- [Loop variable resilient to changes](#loop-variable-resilient-to-changes)
9191
- [💡 Explanation:](#-explanation-22)
92+
- [Let's see if you can guess this?](#lets-see-if-you-can-guess-this)
93+
- [💡 Explanation:](#-explanation-23)
9294
- [Minor Ones](#minor-ones)
9395
- [TODO: Hell of an example!](#todo-hell-of-an-example)
9496
- [Contributing](#contributing)
@@ -220,6 +222,7 @@ Shouldn't that be 100?
220222

221223
### Time for some hash brownies!
222224

225+
1\.
223226
```py
224227
some_dict = {}
225228
some_dict[5.5] = "Ruby"
@@ -1379,8 +1382,9 @@ Before Python 3.5, the boolean value for `datetime.time` object was considered t
13791382

13801383
---
13811384

1382-
### Counting the booleans
1385+
### What's wrong with booleans?
13831386

1387+
1\.
13841388
```py
13851389
# A simple example to count the number of boolean and
13861390
# integers in an iterable of mixed data types.
@@ -1403,6 +1407,21 @@ for item in mixed_list:
14031407
4
14041408
```
14051409

1410+
2\.
1411+
```py
1412+
another_dict = {}
1413+
another_dict[True] = "JavaScript"
1414+
another_dict[1] = "Ruby"
1415+
another_dict[1.0] = "Python"
1416+
```
1417+
1418+
**Output:**
1419+
```py
1420+
>>> another_dict[True]
1421+
"Python"
1422+
```
1423+
1424+
14061425
#### 💡 Explanation:
14071426

14081427
* Booleans are a subclass of `int`
@@ -1413,6 +1432,12 @@ for item in mixed_list:
14131432
True
14141433
```
14151434

1435+
* The integer value of `True` is `1` and that of `False` is `0`.
1436+
```py
1437+
>>> True == 1 == 1.0 and False == 0 == 0.0
1438+
True
1439+
```
1440+
14161441
* See this StackOverflow [answer](https://stackoverflow.com/a/8169049/4354153) for rationale behind it.
14171442

14181443
---

0 commit comments

Comments
 (0)