I got a generator g
, I can use list(g)
or [*g]
to get a list of the items in g
. But what does the "*" mean here?
Asked
Active
Viewed 31 times
0

ncuwlsd
- 11
-
1It means unpacking of values. You can search more on this in Google. – Dinesh Aug 24 '21 at 02:50
-
3Unpacking. Originally it used to be allowed only in the function argument, as in the duplicate Q&A shows. But it is allowed in broader contexts such as `[]`, as in your question (since python 3.5). https://www.python.org/dev/peps/pep-0448/ – j1-lee Aug 24 '21 at 02:50
-
1Please refer to [answer](https://stackoverflow.com/a/40492308/) and [answer](https://stackoverflow.com/a/34166505/) which is found in the linked thread. More information found in all other answers in the thread. – metatoaster Aug 24 '21 at 02:51
-
The * operator is an unpacking operator that will unpack the values from any iterable object, such as lists, tuples, strings. Please checkout this blog https://towardsdatascience.com/unpacking-operators-in-python-306ae44cd480 for detailed information. – Syed Jafer Aug 24 '21 at 02:59