473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Converting tuple into normal value

suppose i get list of tuple as

s = [(2,),(3,)]

now i want to change the value of tuple to

[2,3]

how i can do that
Apr 17 '07 #1
3 1567
bartonc
6,596 Expert 4TB
suppose i get list of tuple as

s = [(2,),(3,)]

now i want to change the value of tuple to

[2,3]

how i can do that
Use a "list comprehension", like this:

>>> s = [(2,),(3,)]
>>> l = [t[0] for t in s]
>>> l
[2, 3]
>>>
Apr 17 '07 #2
bartonc
6,596 Expert 4TB
Use a "list comprehension", like this:

>>> s = [(2,),(3,)]
>>> l = [t[0] for t in s]
>>> l
[2, 3]
>>>
If you deconstruct this to a simpler (as in easier to read) form, it would look like this:
Expand|Select|Wrap|Line Numbers
  1. tupList = [(2,),(3,)]
  2. resultList = []
  3. for tup in tupList:
  4.     resultList.append(tup[0])
  5. print resultList
Once you get used to them, list comprehensions are a great tool.
Apr 17 '07 #3
ghostdog74
511 Expert 256MB
list comprehension is the way to go. just for fun, this is an "unorthordox" way
Expand|Select|Wrap|Line Numbers
  1. import re
  2. >>> map(int,re.findall("(\d+)",str(s)))
  3. [2, 3]
  4.  
Apr 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Krista Bailie | last post by:
I'm sure this is so easy that it will hurt for anyone to read it, but I really need some direction. I'm trying to create a color chart (RGB) that shows steps between two different colors as...
50
by: Will McGugan | last post by:
Hi, Why is that a tuple doesnt have the methods 'count' and 'index'? It seems they could be present on a immutable object. I realise its easy enough to convert the tuple to a list and do this,...
1
by: fedor | last post by:
Hi all, happy new year, I was trying to pickle a instance of a subclass of a tuple when I ran into a problem. Pickling doesn't work with HIGHEST_PROTOCOL. How should I rewrite my class so I can...
5
by: Robert | last post by:
I have a series of web applications (configured as separate applications) on a server. There is a main application at the root and then several virtual directories that are independant...
31
by: metiu uitem | last post by:
Say you have a flat list: How do you efficiently get , , ] I was thinking of something along the lines of: for (key,number) in list: print key, number
9
by: Terry | last post by:
I am converting (attempting) some vb6 code that makes vast use of interfaces. One of the major uses is to be able to split out Read-only access to an obect. Let me give you a simple (contrived)...
5
by: metaperl.etc | last post by:
The following program does not work if you uncomment #lis = + list(args) Evidently Python is opting for the nullary constructor list() as opposed to the other one which takes a sequence....
4
by: pmcgover | last post by:
I enjoyed Paul Barry's September article in Linux Journal entitled, "Web Reporting with MySQL, CSS and Perl". It provides a simple, elegant way to use HTML to display database content without any...
1
by: setori88 | last post by:
Hi guys this script i downloaded from here, http://win32com.goermezer.de/index.php?option=com_content&task=view&id=193&Itemid=274 I copied this script and setup and instance of open office...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.