## Computer-Wiz's Profile User Rating:

Reputation: 1 Apprentice
Group:
Members
Active Posts:
26 (0.02 per day)
Joined:
29-January 11
Profile Views:
1,310
Last Active:
Mar 03 2013 03:37 PM
Currently:
Offline

### Previous Fields

Dream Kudos:
0
Computer-Wiz has not set their status

1. #### In Topic: Bubble Sort Algorithm Animation

Posted 3 Mar 2013

Hi 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()

```
2. #### In Topic: file input and output

Posted 13 Jun 2012

Thanks for all the help and assistance, i really appreciated it, it helped a lot. Now i am able to understand the algorithms more easily.
3. #### In Topic: file input and output

Posted 11 Jun 2012

sorry 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()

```
4. #### In Topic: file input and output

Posted 11 Jun 2012

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
5. #### In Topic: file input and output

Posted 10 Jun 2012

I 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:

apple
mango
orange

*is this what you are asking me?????

Member Title:
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

E-mail:
Private