Skip to content

Commit e2c2cf1

Browse files
committed
Add new snippet: Yielding None
Closes satwikkansal#32
1 parent 2fff92c commit e2c2cf1

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

README.md

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ So, here ya go...
8383
- [💡 Explanation:](#-explanation-18)
8484
- [Needle in a Haystack](#needle-in-a-haystack)
8585
- [💡 Explanation:](#-explanation-19)
86-
- [The surprising comma](#the-surprising-comma)
86+
- [yielding None](#yielding-none)
8787
- [💡 Explanation:](#-explanation-20)
88-
- [For what?](#for-what)
88+
- [The surprising comma](#the-surprising-comma)
8989
- [💡 Explanation:](#-explanation-21)
90-
- [not knot!](#not-knot)
90+
- [For what?](#for-what)
9191
- [💡 Explanation:](#-explanation-22)
92-
- [Let's see if you can guess this?](#lets-see-if-you-can-guess-this)
92+
- [not knot!](#not-knot)
9393
- [💡 Explanation:](#-explanation-23)
94+
- [Let's see if you can guess this?](#lets-see-if-you-can-guess-this)
95+
- [💡 Explanation:](#-explanation-24)
9496
- [Minor Ones](#minor-ones)
9597
- [TODO: Hell of an example!](#todo-hell-of-an-example)
9698
- [Contributing](#contributing)
@@ -1491,6 +1493,38 @@ tuple()
14911493
14921494
---
14931495
1496+
### yielding None
1497+
1498+
Suggested by @chris-rands in [this](https://github.com/satwikkansal/wtfpython/issues/32) issue.
1499+
1500+
```py
1501+
some_iterable = ('a', 'b')
1502+
1503+
def some_func(val):
1504+
return "something"
1505+
```
1506+
1507+
1508+
**Output:**
1509+
```py
1510+
>>> [x for x in some_iterable]
1511+
['a', 'b']
1512+
>>> [(yield x) for x in some_iterable]
1513+
<generator object <listcomp> at 0x7f70b0a4ad58>
1514+
>>> list([(yield x) for x in some_iterable])
1515+
['a', 'b']
1516+
>>> list((yield x) for x in some_iterable)
1517+
['a', None, 'b', None]
1518+
>>> list(some_func((yield x)) for x in some_iterable)
1519+
['a', 'something', 'b', 'something']
1520+
```
1521+
1522+
#### 💡 Explanation:
1523+
- Source and explanation can be found here: https://stackoverflow.com/questions/32139885/yield-in-list-comprehensions-and-generator-expressions
1524+
- Related bug report: http://bugs.python.org/issue10544
1525+
1526+
---
1527+
14941528
### The surprising comma
14951529
14961530
Suggested by @MostAwesomeDude in [this](https://github.com/satwikkansal/wtfPython/issues/1) issue.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy