mercredi 8 juillet 2015

List Index Out of Range: Importing info from two lists into one conditionally

a = "alpha"
b = None
c = "charlie"
first_list = [a,b,c]

a_define = "a"
b_define = "b"
c_define = "c"
second_list = [a_define, b_define, c_define]

third_list = []

len_of_firstlist = len(first_list)

for item in range(len_of_firstlist+1):
    if first_list[item] is not None:
        first_list[item] = first_list[item] + second_list[item]
        third_list.append(first_list[item])

print third_list

This might seem a bit generic unfortunately, but I'm just so lost... The code seems to work, but it keeps giving me an indexing error.

Aucun commentaire:

Enregistrer un commentaire