Re: list to tuple and vice versa

2009-10-20 Thread David C Ullrich
On Sun, 18 Oct 2009 14:33:17 +1100, Ben Finney wrote: > Jabba Laci writes: > >> Hi, >> >> I have some difficulties with list -> tuple conversion: >> >> t = ('a', 'b') >> li = list(t) # tuple -> list, works print li # ['a', 'b'] >> >> tu = tuple(li) # list -> tuple, error print tu # what

Re: list to tuple and vice versa

2009-10-17 Thread StarWing
On 10月18日, 下午1时32分, Ben Finney wrote: > StarWing writes: > > On 10月18日, 下午12时19分, Ben Finney wrote: > > > Jabba Laci writes: > > > > Right, it was my bad. After removal the tuple() function works > > > > perfectly. > > > > Note that, though it is callable, ‘tuple’ is not a function but a > > >

Re: list to tuple and vice versa

2009-10-17 Thread Ben Finney
StarWing writes: > On 10月18日, 下午12时19分, Ben Finney wrote: > > Jabba Laci writes: > > > Right, it was my bad. After removal the tuple() function works > > > perfectly. > > > > Note that, though it is callable, ‘tuple’ is not a function but a > > type: > > A type is always callable. Yes (modulo

Re: list to tuple and vice versa

2009-10-17 Thread StarWing
On 10月18日, 下午12时19分, Ben Finney wrote: > Jabba Laci writes: > > Right, it was my bad. After removal the tuple() function works > > perfectly. > > Note that, though it is callable, ‘tuple’ is not a function but a type: > >     >>> tuple >     >     >>> len >     > > You can use the built-in ‘typ

Re: list to tuple and vice versa

2009-10-17 Thread Ben Finney
Jabba Laci writes: > Right, it was my bad. After removal the tuple() function works > perfectly. Note that, though it is callable, ‘tuple’ is not a function but a type: >>> tuple >>> len You can use the built-in ‘type’ type to get the type of any object: >>> foo = 12

Re: list to tuple and vice versa

2009-10-17 Thread Jabba Laci
>> The error message is: "TypeError: 'tuple' object is not callable". > > You created a variable named "tuple" somewhere, which is shadowing the > built-in type. Rename that variable to something else. Right, it was my bad. After removal the tuple() function works perfectly. Thanks, Laszlo -- h

Re: list to tuple and vice versa

2009-10-17 Thread Ben Finney
Jabba Laci writes: > Hi, > > I have some difficulties with list -> tuple conversion: > > t = ('a', 'b') > li = list(t) # tuple -> list, works > print li # ['a', 'b'] > > tu = tuple(li) # list -> tuple, error > print tu # what I'd expect: ('a', 'b') Works fine for me: Python 2.5.4 (r

Re: list to tuple and vice versa

2009-10-17 Thread Chris Rebert
On Sat, Oct 17, 2009 at 8:24 PM, Jabba Laci wrote: > Hi, > > I have some difficulties with list -> tuple conversion: > > t = ('a', 'b') > li = list(t)   # tuple -> list, works > print li   # ['a', 'b'] > > tu = tuple(li)   # list -> tuple, error > print tu   # what I'd expect: ('a', 'b') > > The e

list to tuple and vice versa

2009-10-17 Thread Jabba Laci
Hi, I have some difficulties with list -> tuple conversion: t = ('a', 'b') li = list(t) # tuple -> list, works print li # ['a', 'b'] tu = tuple(li) # list -> tuple, error print tu # what I'd expect: ('a', 'b') The error message is: "TypeError: 'tuple' object is not callable". Thanks,

Re: list to tuple conversion

2008-10-01 Thread Gabriel Genellina
En Wed, 01 Oct 2008 04:51:33 -0300, sc <[EMAIL PROTECTED]> escribió: Thanx to a recent thread I am able to have a print string with a variable number of formatters -- what I now lack for the creation of an elegant print statement is a tuple -- following is the code, the last line of which does n

Re: list to tuple conversion

2008-10-01 Thread sc
Gary M. Josack wrote: > sc wrote: >> clp: >> >> Thanx to a recent thread I am able to have a print string >> with a variable number of formatters -- what I now lack for >> the creation of an elegant print statement is a tuple -- >> following is the code, the last line of which does not work: >> >>

Re: list to tuple conversion

2008-10-01 Thread Gary M. Josack
sc wrote: clp: Thanx to a recent thread I am able to have a print string with a variable number of formatters -- what I now lack for the creation of an elegant print statement is a tuple -- following is the code, the last line of which does not work: #!/usr/bin/python import xml.sax import e

Re: list to tuple conversion

2008-10-01 Thread Pekka Laukkanen
2008/10/1 sc <[EMAIL PROTECTED]>: > If there were a builtin function that took a list and > returned a tuple, I'd be there, but if there is such a > thing I need someone to point me at it. I can't help > thinking I am missing some obvious construct, and I'll > be advised to go reread the tutorial,

list to tuple conversion

2008-10-01 Thread sc
clp: Thanx to a recent thread I am able to have a print string with a variable number of formatters -- what I now lack for the creation of an elegant print statement is a tuple -- following is the code, the last line of which does not work: #!/usr/bin/python import xml.sax import eaddyhandler p

Re: List to Tuple and Tuple to List?

2007-11-07 Thread Wildemar Wildenburger
Davy wrote: > Hi all, > > I am curious about whether there is function to fransform pure List to > pure Tuple and pure Tuple to pure List? > Isn't that just the same topic as in your other thread? I think it is somewhat unfriendly that you ignore that one. It makes me feel that you see this grou

Re: List to Tuple and Tuple to List?

2007-11-06 Thread Boris Borcic
Davy wrote: > Hi all, > > I am curious about whether there is function to fransform pure List to > pure Tuple and pure Tuple to pure List? > > For example, > > I have list L = [[1,2,3],[4,5,6]] > something list2tuple() will have T=list2tuple(L)=((1,2,3),(4,5,6)) > > And the tuple2list() > > An

Re: List to Tuple and Tuple to List?

2007-11-06 Thread Paul Hankin
On Nov 6, 11:18 am, Davy <[EMAIL PROTECTED]> wrote: > Hi all, > > I am curious about whether there is function to fransform pure List to > pure Tuple and pure Tuple to pure List? > > For example, > > I have list L = [[1,2,3],[4,5,6]] > something list2tuple() will have T=list2tuple(L)=((1,2,3),(4,5,

List to Tuple and Tuple to List?

2007-11-06 Thread Davy
Hi all, I am curious about whether there is function to fransform pure List to pure Tuple and pure Tuple to pure List? For example, I have list L = [[1,2,3],[4,5,6]] something list2tuple() will have T=list2tuple(L)=((1,2,3),(4,5,6)) And the tuple2list() Any suggestions are welcome! Best regar

Re: list to tuple

2005-08-11 Thread zxo102
Thanks for your help. -- http://mail.python.org/mailman/listinfo/python-list

Re: list to tuple

2005-08-11 Thread Paddy
Try this: >>> a,b,c = list('tab'),list('era'),list('net') >>> a,b,c (['t', 'a', 'b'], ['e', 'r', 'a'], ['n', 'e', 't']) >>> tuple(((x,y,z) for x,y,z in zip(a,b,c))) (('t', 'e', 'n'), ('a', 'r', 'e'), ('b', 'a', 't')) >>> - Paddy. -- http://mail.python.org/mailman/listinfo/python-list

Re: list to tuple

2005-08-11 Thread Ruslan Spivak
"zxo102" <[EMAIL PROTECTED]> writes: > Hi, >I got several dynamic lists a1, b1, c1, from a python > application such as >a1 = [1,5,3,2,5,...], the len(a1) varies. Same to b1, c1, > >With python, I would like to reorganize them into a tuple like > >t1 = ((a1[0],b1[0],c1[0]

Re: list to tuple

2005-08-11 Thread James Stroud
Try the zip funciton: py> a = [11,12,13,14] py> b = [2,3,4,5] py> c = [20,21,22,23,24,25] py> zip(a,b,c) [(11, 2, 20), (12, 3, 21), (13, 4, 22), (14, 5, 23)] On Thursday 11 August 2005 09:05 pm, zxo102 wrote: > Hi, >I got several dynamic lists a1, b1, c1, from a python > application

list to tuple

2005-08-11 Thread zxo102
Hi, I got several dynamic lists a1, b1, c1, from a python application such as a1 = [1,5,3,2,5,...], the len(a1) varies. Same to b1, c1, With python, I would like to reorganize them into a tuple like t1 = ((a1[0],b1[0],c1[0],...),(a1[1],b1[1],c1[1],...),...) Anybody knows