Terry Reedy wrote:
a,b,*rest = list(range(10))
The list() call is superfluous.
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, May 28, 2009 at 3:57 PM, Terry Reedy tjre...@udel.edu wrote:
guthrie wrote:
I want to do a functional like pattern match to get teh first two
elements, and then the rest of an array return value.
For example, assume that perms(x) returns a list of values, and I want
to do this:
Peter Otten wrote:
Terry Reedy wrote:
a,b,*rest = list(range(10))
The list() call is superfluous.
Agreed, even in Py3 when range() returns a range object rather than a list.
--
http://mail.python.org/mailman/listinfo/python-list
I want to do a functional like pattern match to get teh first two
elements, and then the rest of an array return value.
For example, assume that perms(x) returns a list of values, and I want
to do this:
seq=perms(x)
a = seq[0]
b = seq[1]
rest = seq[2:]
Of course I can shorten to:
guthrie wrote:
I want to do a functional like pattern match to get teh first two
elements, and then the rest of an array return value.
For example, assume that perms(x) returns a list of values, and I want
to do this:
seq=perms(x)
a = seq[0]
b = seq[1]
rest = seq[2:]
Of course
On May 28, 5:43 pm, guthrie guth...@mum.edu wrote:
I want to do a functional like pattern match to get teh first two
elements, and then the rest of an array return value.
For example, assume that perms(x) returns a list of values, and I want
to do this:
seq=perms(x)
a = seq[0]
Terry Reedy:
a,b,*rest = list(range(10))
a,b,rest
(0, 1, [2, 3, 4, 5, 6, 7, 8, 9])
a,*rest,b = 'abcdefgh'
a,rest,b
('a', ['b', 'c', 'd', 'e', 'f', 'g'], 'h')
For the next few years I generally suggest to specify the Python
version too (if it's 2.x or 3.x).
This is Python 3.x.
Bye,
On Thu, 28 May 2009 18:57:42 -0400, Terry Reedy wrote:
a,b,*rest = list(range(10))
That fails in Python 2.5 and 2.6.
a,b,*rest = list(range(10))
File stdin, line 1
a,b,*rest = list(range(10))
^
SyntaxError: invalid syntax
--
Steven
--
Many thanks to all; perfect solution!
--
http://mail.python.org/mailman/listinfo/python-list