Python Forum
How i can add elements to table index of element
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How i can add elements to table index of element
#1
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)
Reply
#2
you have rozmiar attribute twice on line 12,
change to once.
Reply
#3
once does not work
Reply
#4
it's append, not insert.
and attribute only once
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sorting Elements via parameters pointing to those elements. rpalmer 3 322 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  Adding List Element if Second part of the List Elements are the Same quest_ 3 357 Nov-25-2020, 04:33 PM
Last Post: bowlofred
  How to get index of minimum element between 3 & 8 in list Mekala 2 335 Nov-10-2020, 12:56 PM
Last Post: DeaD_EyE
  Fetch Oracle DB rows & print it in HTML file with table's col headers in table format tssr_2001 1 665 Sep-04-2020, 01:39 PM
Last Post: ibreeden
  Mysql CREATE TABLE IF NOT EXISTS dynamic table name nisusavi 0 515 Apr-29-2020, 06:45 PM
Last Post: nisusavi
  MYSQL how to assign a table for each user in my username table database? YoshikageKira 1 1,000 Dec-26-2019, 05:57 AM
Last Post: buran
  change array elements dependent on index SchroedingersLion 1 570 Nov-22-2019, 06:25 AM
Last Post: scidam
  Select a part of an element of a list with Index BollerwagenIng 0 745 Aug-09-2019, 09:27 AM
Last Post: BollerwagenIng
  Unable to locate element no such element gahhon 6 1,435 Feb-18-2019, 02:09 PM
Last Post: gahhon
  Change single element in 2D list changes every 1D element AceScottie 9 5,313 Nov-13-2017, 07:05 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020