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
  Variable for the value element in the index function?? Learner1 8 541 Jan-20-2024, 09:20 PM
Last Post: Learner1
  ValueError: Length mismatch: Expected axis has 8 elements, new values have 1 elements ilknurg 1 5,011 May-17-2022, 11:38 AM
Last Post: Larz60+
  pandas pivot table: How to find count for each group in Index and Column JaneTan 0 3,225 Oct-23-2021, 04:35 AM
Last Post: JaneTan
  myList.insert(index, element) question ChrisF 1 1,608 Aug-27-2021, 03:49 PM
Last Post: bowlofred
  Sorting Elements via parameters pointing to those elements. rpalmer 3 2,547 Feb-10-2021, 04:53 PM
Last Post: rpalmer
  Adding List Element if Second part of the List Elements are the Same quest_ 3 2,376 Nov-25-2020, 04:33 PM
Last Post: bowlofred
  How to get index of minimum element between 3 & 8 in list Mekala 2 2,465 Nov-10-2020, 12:56 PM
Last Post: DeaD_EyE
  change array elements dependent on index SchroedingersLion 1 2,167 Nov-22-2019, 06:25 AM
Last Post: scidam
  Select a part of an element of a list with Index BollerwagenIng 0 1,824 Aug-09-2019, 09:27 AM
Last Post: BollerwagenIng
  Unable to locate element no such element gahhon 6 4,368 Feb-18-2019, 02:09 PM
Last Post: gahhon

Forum Jump:

User Panel Messages

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