Reputation: 1 Apprentice
- Active Posts:
- 26 (0.03 per day)
- 29-January 11
- Profile Views:
- Last Active:
- Mar 03 2013 03:37 PM
- Dream Kudos:
Posts I've Made
Posted 3 Mar 2013Hi there, so i updated this code to organize it more but i still cant get it to do what i wanted. It still gives me the same output.
''' Created on Sep 12, 2010 @author: aaronkilpatrick ''' from Tkinter import* import time def bubbleSort(lst): for number in range(len(lst)-1, 0, -1): for i in range(number): if lst[i] > lst[i + 1]: lst[i], lst[i + 1] = lst[i + 1], lst[i] print lst for j in lst: cv.delete([j]) animation() cv.delete(ALL) cv.update() def animation(): x , y = 220, 500 barWidth = 15 for item in lst: cv.delete([item]) bar = cv.create_rectangle(x, y, x+barWidth, y-(item*15), fill="red") x += barWidth + 5 time.sleep(0.2) cv.update() #MAIN #Canvas root = Tk() root.title("Sorting Algorithm Animation") w = 800 h = 600 cv = Canvas(width=w, height=h, bg='black') cv.pack() cv.update() lst = [1,2,7,3,6,4,5,10,8,9,12,15,11,13,16,14,20,17,19,18] bubbleSort(lst) animation() root.mainloop()
Posted 13 Jun 2012Thanks for all the help and assistance, i really appreciated it, it helped a lot. Now i am able to understand the algorithms more easily.
Posted 11 Jun 2012sorry this is the actual code that i just recently did:
fileIn = open ("listOfFruits.txt", "r") fileOut = open ("newListOfFruits.txt", "w") line = for currentLine in fileIn: line.append(currentLine.strip()) line.sort() for items in line: fileOut.write(items) fileIn.close() fileOut.close()
Posted 11 Jun 2012sorry for replying so late.
But i worked on this a little and i came up with another way but this time i am just having problem with writing the items in the list one by one to the next document.
line =  fileIn = open ("listOfFruits.txt", "r") fileOut = open ("newListOfFruits.txt", "w") for currentLine in fileIn: line.append(currentLine) for items in line: line.sort() fileOut.write(items.strip() + "\n") print line fileIn.close() fileOut.close()
I understood the part about sorting it once and removing all them from being a list into one list. But now i am still stuck on printing the output to the file
Posted 10 Jun 2012I am trying to write the words one at a time. so all the items in my list are written separately. So if my list is [orange, mango, apple] i want the file to be written like:
*is this what you are asking me?????
- Member Title:
- New D.I.C Head
- Age Unknown
- Birthday Unknown