Python Forum
How i can add elements to table index of element - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How i can add elements to table index of element (/thread-31299.html)



How i can add elements to table index of element - blazej2533 - Dec-03-2020

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)



RE: How i can add elements to table index of element - Larz60+ - Dec-03-2020

you have rozmiar attribute twice on line 12,
change to once.


RE: How i can add elements to table index of element - blazej2533 - Dec-03-2020

once does not work


RE: How i can add elements to table index of element - Larz60+ - Dec-03-2020

it's append, not insert.
and attribute only once