나는 사전을 정렬하기위한 현재 알고리즘을 가지고 있지만 4 개 이상의 요소를 비교하면 작동하지 않을 것입니다. 내가 도대체 뭘 잘못하고있는 겁니까?거품 정렬을 사용하여 파이썬에서 사전을 정렬하는 방법
database={
0:['Ninna','Layug','201504584','09954895032','Quezon City','[email protected]','18','02/21/1999'],
1:['Yela','Gregorio','201506070','09984548540','UP Diliman','[email protected]','19','04/18/1999'],
2:['Denise','Gregorio','201506070','09984548540','UP Diliman','[email protected]','19','04/18/1999'],
3:['Alia','Layug','201504584','09954895032','Quezon City','[email protected]','18','02/21/1999'],
4:['Keeno','Layug','201504584','09954895032','Quezon City','[email protected]','18','02/21/1999']
}
profiles=['0','1','2','3','4']
for x in range(len(profiles)):
print(profiles)
for j in range(len(profiles)-1-x):
v1=database[j][0]
v2=database[j+1][0]
if v1>v2:
sorted=False
temp=profiles[j+1]
profiles[j+1]=profiles[j]
profiles[j]=temp
for x in profiles:
print(database[int(x)][0],",",database[int(x)][1])
'sort'를 사용하는 대신 고유 한 정렬 알고리즘을 구현하는 특별한 이유가 있습니까? – Kevin
가능한 [Bubble Sort Homework] (http://stackoverflow.com/questions/895371/bubble-sort-homework) 중복 가능 –