篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Resultado do dojo de python - 04/05/2017相关的知识,希望对你有一定的参考价值。
import unittest
from morse import Morse
class Test_Morse(unittest.TestCase):
def testStringToMorse(self):
m = Morse();
self.assertEqual("... --- ...", m.StringToMorse("SOS"))
self.assertEqual("... --- ...", m.StringToMorse("sos"))
self.assertEqual("... --- ...", m.StringToMorse(" sos "))
if __name__=='__main__':
unittest.main()
class BubbleSort:
def sort(self, lista):
for x in (range(1,len(lista))):
if lista[x - 1] > lista[x]:
aux = lista[x-1]
lista[x-1] = lista[x]
lista[x] = aux
return lista
#http://interactivepython.org/courselib/static/pythonds/SortSearch/TheBubbleSort.html
def bubbleSort(alist):
for passnum in range(len(alist)-1,0,-1):
for i in range(passnum):
if alist[i]>alist[i+1]:
temp = alist[i]
alist[i] = alist[i+1]
alist[i+1] = temp
alist = [54,26,93,17,77,31,44,55,20]
bubbleSort(alist)
print(alist)
class Sort:
def run(self, items):
for i in range(len(items)):
for j in range(len(items)-1-i):
if items[j] > items[j+1]:
items[j], items[j+1] = items[j+1], items[j]
return items
* https://docs.google.com/presentation/d/1VQOoaa2BoQwJS-2OCoSP7p19RvFezKfKFolYR_5tma8/edit[Slides]
* https://ide.c9.io/adamatti/learn-python[Workspace no cloud9]