Re: List--->Tuple?

Steven D. Majewski (sdm7g@virginia.edu)
Wed, 5 Apr 1995 00:19:45 -0400 (EDT)

On 4 Apr 1995, Marko Balabanovic wrote:

> Is there an easy way to convert a list to a tuple?
>
> I need something which will take [a,b,c] and output (a,b,c), so that I can then
> use it as part of a dictionary key.
>

In an attempt to frustrate my Obfuscated Python contests, Guido added
( it's in 1.1 at least, maybe before - I don't remember ) a builtin
function 'tuple' that converts any sequence into a tuple:

>>> tuple( [1,2,3] )
(1, 2, 3)
>>> tuple( 1,2,3 )
(1, 2, 3)
>>> tuple( 'abc' )
('a', 'b', 'c')
>>> import array
>>> tuple(array.array( 'i' , range( 10 ) ))
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

---| Steven D. Majewski (804-982-0831) <sdm7g@Virginia.EDU> |---
---| Computer Systems Engineer University of Virginia |---
---| Department of Molecular Physiology and Biological Physics |---
---| Box 449 Health Science Center Charlottesville,VA 22908 |---