add elements to indexed list locations

leventyilmaz at leventyilmaz at
Fri Jun 16 19:17:45 CEST 2006


I have a very simple problem, but do not know an elegant way to
accomplish this.
# I have a list of names:
names = ['clark', 'super', 'peter', 'spider', 'bruce', 'bat']

# and another set of names that I want to insert into
# the names list at some indexed locations:
surnames = { 1: 'kent', 3:'parker', 5:'wayne' }

# The thing I couldn't figure out is, after I insert a
# surname the rest of the indices are not valid.
# That is, the following won't work:
for i, x in surnames.iteritems():

I am searching a nice way to do this. For instance, is there a more
robust way to store indices (as some sort of pointers maybe?) 

- Levent

More information about the Python-list mailing list