[Tutor] don't understand iteration

Alex Kleider akleider at sonic.net
Tue Nov 11 18:38:29 CET 2014


On 2014-11-11 06:19, eryksun wrote:
> On Tue, Nov 11, 2014 at 4:52 AM, Alan Gauld <alan.gauld at btinternet.com> 
> wrote:

> 
> Python 3 extended unpacking:
> 
>     >>> a, *bcd, e = 'abcde'
>     >>> a
>     'a'
>     >>> bcd
>     ['b', 'c', 'd']
>     >>> e
>     'e'


Seeing the above in a recent post, it made me wonder what would happen 
if the string had only two characters.  All went well and I'm wondering 
if I've stumbled across a solution to a problem I don't yet know 
about:-)

b, *m, e = 'abcdefghi'  # Length can be even or odd.
while m:
     print(b, m, e, sep='/')
     b, *m, e = m




More information about the Tutor mailing list