Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with list
#4
Ok no i got a new problem with the code. when im use append to continue adding to the list it over writes it instead of adding new data. i tryed extend to getting the same problem.

this is how i wanted to print

Quote:test1-1-1-1
test1-1-2-2
test1-1-3-3
test2-2-1-1
test2-2-2-2
test2-2-3-3

instead i get the last added data when i print the list like this.

Quote:test2-2-1-1
test2-2-2-2
test2-2-3-3


this is my code so far.
    def funktion(self):
        value1 = (self.a1.get())
        value2 = (self.a2.get())
        value3 = (self.a3.get())
        value4 = (self.a4.get())
        value5 = (self.a5.get())
        self.mylist = []
        
        for parts in range(value3-1, value5):
            #print('{}-{}-{}-{}\n'.format(value1, value2, parts+1, parts+1))
            #self.text_entry.insert(END, '{}-{}-{}-{}\n'.format(value1, value2, parts+1, parts+1))
            self.mylist.append('{}-{}-{}-{}'.format(value1, value2, parts+1, parts+1))
        print ('\n'.join(self.mylist))

    def file_save(self):
        print ('\n'.join(self.mylist))
Reply


Messages In This Thread
problem with list - by darktitan - Jul-27-2018, 03:51 PM
RE: problem with list - by ichabod801 - Jul-27-2018, 07:00 PM
RE: problem with list - by darktitan - Jul-27-2018, 10:13 PM
RE: problem with list - by darktitan - Jul-28-2018, 06:34 AM
RE: problem with list - by Axel_Erfurt - Jul-28-2018, 07:11 AM
RE: problem with list - by darktitan - Jul-28-2018, 07:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem with "Number List" problem on HackerRank Pnerd 5 2,163 Apr-12-2022, 12:25 AM
Last Post: Pnerd

Forum Jump:

User Panel Messages

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