[Tutor] How to convert a list to tuple
Srinivas Iyyer
srini_iyyer_bio at yahoo.com
Wed Nov 16 22:22:16 CET 2005
Thanks. It works.
Thanks for simplifying it in list comprehension.
Srini
--- Liam Clarke-Hutchinson
<Liam.Clarke-Hutchinson at business.govt.nz> wrote:
> Does this work? (I can't check)
>
> listX = ['933\t957', '955\t979', '969\t993',
> '1025\t1049', '1052\t1076',
> '1098\t1122', '1136\t1160', '1298\t1322',
> '1406\t1430', '1422\t1446',
> '1471\t1495']
>
> listY = [ tuple(item.split("\t")) for item in listX]
> tupleY = tuple(listY)
>
> Liam Clarke-Hutchinson| Contact Centre Advisor|
> Ministry of Economic
> Development
> DDI +64 3 962 2639 | Fax +64 3 962 6220
> www.med.govt.nz
>
>
>
> -----Original Message-----
> From: tutor-bounces+ml.cyresse=gmail.com at python.org
>
[mailto:tutor-bounces+ml.cyresse=gmail.com at python.org]
> On Behalf Of Srinivas
> Iyyer
> Sent: Thursday, 17 November 2005 9:59 a.m.
> To: tutor at python.org
> Subject: [Tutor] How to convert a list to tuple
>
>
> Dear all,
> Pardon me for asking a simple question. Sometimes
> brain gets blank and compells me to seek help from
> tutors.
>
> I have a list :
> >>>prcor
> ['933\t957', '955\t979', '969\t993', '1025\t1049',
> '1052\t1076',
> '1098\t1122', '1136\t1160', '1298\t1322',
> '1406\t1430', '1422\t1446',
> '1471\t1495']
> >>> prc = ()
> >>>for line in prcor:
> cols = line.split('\t')
> (x,y) = (int(cols[0]),int(cols[1]))
> prc = (x,y)
> >>>prc
> (1471, 1495)
>
> Because the resulting element is a tuple, append is
> not working.
>
> How can I push all these elements in this list:
> ['933\t957', '955\t979', '969\t993', '1025\t1049',
> '1052\t1076',
> '1098\t1122', '1136\t1160', '1298\t1322',
> '1406\t1430', '1422\t1446',
> '1471\t1495']
>
> into a a big tuple :
>
>
((933,957),(955,979),(969,993),(1025,1049),(1052,1076),(1098,1122),(1136,116
> 0),
> (1298,1322),(1406,1430),(1422,1446),(1471,1495))
>
>
> Thank you.
>
>
>
>
>
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
> A new monthly electronic newsletter covering all
> aspects of MED's work is now available. Subscribers
> can choose to receive news from any or all of seven
> categories, free of charge: Growth and Innovation,
> Strategic Directions, Energy and Resources, Business
> News, ICT, Consumer Issues and Tourism. See
> http://news.business.govt.nz for more details.
>
>
>
>
> http://www.govt.nz - connecting you to New Zealand
> central & local government services
>
> Any opinions expressed in this message are not
> necessarily those of the Ministry of Economic
> Development. This message and any files transmitted
> with it are confidential and solely for the use of
> the intended recipient. If you are not the intended
> recipient or the person responsible for delivery to
> the intended recipient, be advised that you have
> received this message in error and that any use is
> strictly prohibited. Please contact the sender and
> delete the message and any attachment from your
> computer.
>
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
More information about the Tutor
mailing list