NEW TO THIS: Assigning values to strings in list?

Sean 'Shaleh' Perry shalehperry at attbi.com
Fri Jul 19 12:17:25 EDT 2002


On 19-Jul-2002 Johannes Graumann wrote:
> Hello,
> 
> As stated in the subject, I'm new to this - but I think with this 
> question I might be already headed for my first good burn ;0)
> 
> Basicely I have two lists, one containing the future string-names 
> and one containing the values I want to give them. The order is
> identical in both. Right now I'm solving this by a dictionary, but 
> I would really prefer to have straight strings as a result of my 
> operation.
> 
> Can anybody please tell me how to go about this and/or why I 
> totally shouldn't do this?
> 

so you have:

a_list = ['sean', 'johannes', 'margaret']

and

b_list = ['this', 'other', 'fellow']

and you just want to swap their values?  Why not just assign b_list to a_list?

a_list = b_list

Otherwise you have to muck with counters.

for i in range(0, len(a_list)):
  a_list[i] = b_list[i]

If none of this helped, provide some more detail, perhaps a small code snippet.

Also, tutor at python.org is a great place for those "new to this" to hang out,
ask questions and see other people's questions.  You can learn a lot by just
lurking and reading.





More information about the Python-list mailing list