Python Forum

Full Version: How i can add elements to table index of element
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello
I want to add an element to the list. I want this element to be on the list under the index as high as this element. If an item is already occupied, I want to add it to the next free item.
w pliku mam słowa, które zmieniam na znaki ASCII
for example input:(after converting)
table = [5,5,7,1,2,3,6]


Output:
table[0]=None table[1]=1 table[2]=2 table[3]=3 table[4]=None table[5]=5 table[6]=5 table[7]=6 table[8]=7
my code:
file = open('C:/Users/Błażej/Desktop/znaki.txt', 'r').read()
lines = file.split('\n')
table = []
table2=[]
for line in lines:
    lista=list(line)
    result=0
    for elem in lista:
        result+=int(ord(elem))
    rozmiar=result%1013
    table.append(rozmiar)
    table2.insert(rozmiar, rozmiar)
print(table2)
you have rozmiar attribute twice on line 12,
change to once.
once does not work
it's append, not insert.
and attribute only once