getting info out of a list.

Alex Martelli aleax at aleax.it
Sun Jun 15 04:55:58 EDT 2003


<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:

    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





More information about the Python-list mailing list