[Python-Dev] Tuple/list assignment question (original) (raw)
Dave Cole djc at object-craft.com.au
Wed Aug 4 01:55:49 CEST 2004
- Previous message: [Python-Dev] Tuple/list assignment question
- Next message: [Python-Dev] Tuple/list assignment question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Nick Coghlan wrote:
Dave Cole wrote:
Is there any reason why something like this would not be a good idea?
>>> alist = [1, 2, 3, 4, 5] >>> a, b, *c = alist You could then do things like this: >>> lol = [[1, 2], [3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13]] >>> for a, b *c in lol: ... - Dave As opposed to: >>> for a, b, c in ((x[0], x[1], x[2:]) for x in lol): print a, b, c
Yes, as opposed to.
With generator expressions around, I don't know that this case is common enough for special casing. . .
This begs the question; do you prefer:
args = [4, 5, 6] a_func(1, *args)
or this:
args = [4, 5, 6] apply(a_func, [1] + args)
- Dave
-- http://www.object-craft.com.au
- Previous message: [Python-Dev] Tuple/list assignment question
- Next message: [Python-Dev] Tuple/list assignment question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]