473,472 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I got it! How to force a single number to be a tuple

Sorry for the previous message. It's really a simple question and I have
solved it myself.

Thanks,

Jinming

------------------------------------------------------------------------
Hi Folks,

I have a number sequence, which is put into a tuple like this:

y=2, 3.0, 4.5

I can manipulate the sequence as a tuple when it has more than 1 number. But
when the sequence has only 1 number, like

y=2

I have trouble to manipulate it as a tuple. I guess there must be a way to
forece a single number to be a tuple. Could anyone please tell me that?

Thanks,

Jinming

__________________________________________________ _______________
Discover the best of the best at MSN Luxury Living. http://lexus.msn.com/

Jul 18 '05 #1
3 1362
Jinming Xu wrote:
Sorry for the previous message. It's really a simple question and I have
solved it myself.

Thanks,

Jinming

------------------------------------------------------------------------
Hi Folks,

I have a number sequence, which is put into a tuple like this:

y=2, 3.0, 4.5

I can manipulate the sequence as a tuple when it has more than 1 number.
But when the sequence has only 1 number, like

y=2

I have trouble to manipulate it as a tuple. I guess there must be a way
to forece a single number to be a tuple. Could anyone please tell me that?

Thanks,

Jinming

__________________________________________________ _______________
Discover the best of the best at MSN Luxury Living. http://lexus.msn.com/

Jinming,
t = (1)
t 1 t = (1,)
t (1,)

wes

Jul 18 '05 #2


Jinming Xu wrote:
Sorry for the previous message. It's really a simple question and I have
solved it myself.

Thanks,

Jinming

------------------------------------------------------------------------
Hi Folks,

I have a number sequence, which is put into a tuple like this:

y=2, 3.0, 4.5

I can manipulate the sequence as a tuple when it has more than 1 number.
But when the sequence has only 1 number, like

y=2

I have trouble to manipulate it as a tuple. I guess there must be a way
to forece a single number to be a tuple. Could anyone please tell me that?

Thanks,

Jinming

__________________________________________________ _______________
Discover the best of the best at MSN Luxury Living. http://lexus.msn.com/

Maybe something like:
[Dbg]>>> y= 6
[Dbg]>>> if not isinstance(x, (tp.ListType, tp.TupleType)):
[Dbg]... y= (y, )
[Dbg]...
[Dbg]>>> print y
(6,)
[Dbg]>>>
Colin W.

Jul 18 '05 #3
y=2,
The comma makes tuples.
y=2, 3.0, 4.5,
also works.

Are you sure that you want a list of numbers as an immutable tuple?
Tuples are intended for hetrogenious sequences like a data record,
(like y=2, 3.0, 4.5 is a record of say quantity, price and weight,
and y=3.0, 2, 4.5 is a completely different thing).
Tuples can be used as an index in a dictionary.

A list is mutable, intended for a homogenious sequence, the elements
can be changed and a list can not be used a dictionary index.
(like y=[2, 3.0, 4.5] is a list of the weights of three items and
y=[3.0, 2, 4.5] has the same meaning)

Thanks,
Jeff Sandys

Jinming Xu wrote:

Sorry for the previous message. It's really a simple question and I have
solved it myself.

Thanks,

Jinming

------------------------------------------------------------------------
Hi Folks,

I have a number sequence, which is put into a tuple like this:

y=2, 3.0, 4.5

I can manipulate the sequence as a tuple when it has more than 1 number. But
when the sequence has only 1 number, like

y=2

I have trouble to manipulate it as a tuple. I guess there must be a way to
forece a single number to be a tuple. Could anyone please tell me that?

Thanks,

Jinming

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jinming Xu | last post by:
Hi Folks, I have a number sequence, which is put into a tuple like this: y=2, 3.0, 4.5 I can manipulate the sequence as a tuple when it has more than 1 number. But when the sequence has...
66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
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...
11
by: vdavidster | last post by:
Hello everyone, I want to convert a tuple to a list, and I expected this behavior: list(('abc','def')) -> list(('abc')) -> But Python gave me this behavior: list(('abc','def')) ->
3
by: Ken Durden | last post by:
Is it possible to force positive values to have the + sign prefixed on them? double f1 = 1024.2; double f2 = -1024.2; string.Format( "{0:F}", f1 ); // +1024.2 string.Format( "{0:F}", f2 );...
11
by: ago | last post by:
Inspired by some recent readings on LinuxJournal and an ASPN recipe, I decided to revamp my old python hack... The new code is a combination of (2) reduction methods and brute force and it is quite...
2
by: Alan Isaac | last post by:
I am probably confused about immutable types. But for now my questions boil down to these two: - what does ``tuple.__init__`` do? - what is the signature of ``tuple.__init__``? These...
1
by: Thirdworld | last post by:
I have a table called Contacts that hold the name of the contact, the phone number and the e-mail address. I'm trying to create an update query that can change the phone number or e-mail address for...
1
by: Alex Vinokur | last post by:
Hi, Is it possible to get number of elements in the tuple boost? For instance, boost::tuple<int, string, boolt; Number of elements in that tuple is 3. I need to get that number.
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.