getting info out of a list.

Jim Richardson warlock at eskimo.com
Sun Jun 15 22:19:56 CEST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, 15 Jun 2003 08:55:58 GMT,
 Alex Martelli <aleax at aleax.it> wrote:
><posted & mailed>
> 
> Jim Richardson wrote:
> 
>> I have the following code
>> 
>> for wires in wirelist.keys():
>>         bits=wirelist[wires]
>>         Wire=("GW",wires,bits)
>>         print Wire
>> 
>> 
>> Which, depending on the data in wirelist, results in something like,
>> 
>> ('GW', 1, (11, 0, -500, 0, 0, 500, 0, 10))
>> 
>> 
>> But what I want is
>> 
>> ('GW', 1, 11, 0, -500, 0, 0, 500, 0, 10)
>> 
>> I want the tuple that is returned from the dict wirelist, to be added as
>> individual elements, rather than a tuple of individual elements, to the
>> list "bits"
>> 
>> (I hope I have explained this properly)
> 
> Well, not quite -- there seems to be some tuple-vs-lits confusions in
> your text vs your code, as well as some confusion as to what gets added
> to what else.  But I think what you want is, roughly:
> 

I think the confusion is that the data stuffed into the dict earlier,
consisted of a tuple. I wasn't clear on that part I think. 

>     Wire = ('GW', wires) + wirelist[wires]
> 
> i.e., you want to CONCATENATE the wirelist[wires] tuple right after
> the two-items tuple whose first item is 'GW' and whose second item
> is wires.  Python does express sequence concatenation as 'adding'
> (i.e., it uses the plus sign to indicate it).
> 
> 
> Alex
> 


Bingo! that was it, thank you very much. 

I knew I was missing something fundamental. 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+7NTrd90bcYOAWPYRAmPlAKDMypc5D9PRwoPZJF8XHi0t651k6ACcCibP
da79gXGBKq5SfVQUHxR6sK0=
=v1lL
-----END PGP SIGNATURE-----

-- 
Jim Richardson         http://www.eskimo.com/~warlock

Linux, because eventually, you grow up enough to be trusted with a fork()




More information about the Python-list mailing list