[Tutor] don't understand iteration
Clayton Kirkwood
crk at godblessthe.us
Tue Nov 11 01:28:25 CET 2014
>-----Original Message-----
>From: Tutor [mailto:tutor-bounces+crk=godblessthe.us at python.org] On
>Behalf Of Ben Finney
>Sent: Sunday, November 09, 2014 8:25 PM
>To: tutor at python.org
>Subject: Re: [Tutor] don't understand iteration
>
>"Clayton Kirkwood" <crk at godblessthe.us> writes:
>
>> >-----Original Message-----
>> >From: Tutor [mailto:tutor-bounces+crk=godblessthe.us at python.org] On
>> >Behalf Of Dave Angel
>
>(Clayton, does your mail client not present messages written by their
>authors? The messages should not come to you “From:” the tutor list
>itself. It's awkward to follow whom you're quoting.)
>
>> >(month, day, time, ap, offset) = blah.group( *list (range (1, 6)))
>> >
>> >Should do it.
>
>> Where did you find that one?
>
>Working through the Python Tutorial (actually doing the examples, and
>working to understand them before moving on) teaches these and other
>Python concepts <URL:https://docs.python.org/3/tutorial/>.
>
>> What does the '*' do/why?
>
>Learn about sequence unpacking in function parameters at the Tutorial
><URL:https://docs.python.org/3/tutorial/controlflow.html#tut-unpacking-
>arguments>.
This seems to be the only relevant words:
4.7.4. Unpacking Argument Lists
The reverse situation occurs when the arguments are already in a list or tuple but need to be unpacked for a function call requiring separate positional arguments. For instance, the built-in range() function expects separate start and stop arguments. If they are not available separately, write the function call with the *-operator to unpack the arguments out of a list or tuple:
>>> list(range(3, 6)) # normal call with separate arguments
[3, 4, 5]
>>> args = [3, 6]
>>> list(range(*args)) # call with arguments unpacked from a list
[3, 4, 5]
I fail to see the reference to '* list' except for possibly the '*-operator', for which there is no example or further guidance of this far too often used ability. And possibly later the reference to '*args' which appears to act as a wildcard/expander/replacement for the more exacting [3,6].
The only other places where I saw something like a '*list' was way off in PyObject and daughters suggesting a C char * or pointer. I'm sure I don't need to get into that just to find a reference to something so obvious as a '*list', something that I run across all of the time.
I'm gettin' older and I can see out of one eye and not so good out of the other so I have to rotate the page 180 degrees to read the other half of the page and sometimes readin' upside down gives me difficulty and I miss '*'s every once in a while.
Clayton
PS, I'd still like to find a discussion and usage examples of this all too common '*list'. Thanks
>
>> And why the weird range thing?
>
>Learn about the ‘range’ built-in at the Python library reference
><URL:https://docs.python.org/3/library/functions.html#func-range>.
>
>--
> \ “I went to the museum where they had all the heads and arms |
> `\ from the statues that are in all the other museums.” —Steven |
>_o__) Wright |
>Ben Finney
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list