>> print ','< '1'<'A'<'a'<'阿' True
>> print '曙'< '鲑','曾'<'怡' True True
# encoding=utf8
char=['赵','钱','孙','李','佘']
char.sort()
for item in char:
print item.decode('utf-8').encode('gb2312')
# encoding=gb2312 char=['赵','钱','孙','李','佘'] char.sort() for item in char: print item
# 建立拼音辞典
dic_py = dict()
f_py = open('py.txt','r')
content_py = f_py.read()
lines_py = content_py.split('\n')
n=len(lines_py)
for i in range(0,n-1):
word_py, mean_py = lines_py[i].split('\t', 1)
dic_py[word_py]=mean_py
f_py.close()
# 辞典查找函数
def searchdict(dic,uchar):
if isinstance(uchar, str):
uchar = unicode(uchar,'utf-8')
if uchar >= u'\u4e00' and uchar < = u'\u9fa5':
value=dic.get(uchar.encode('utf-8'))
if value == None:
value = '*'
else:
value = uchar
return value
#比较单个字符
def comp_char_PY(A,B):
if A==B:
return -1
pyA=searchdict(dic_py,A)
pyB=searchdict(dic_py,B)
if pyA > pyB:
return 1
elif pyA < pyB:
return 0
else:
bhA=eval(searchdict(dic_bh,A))
bhB=eval(searchdict(dic_bh,B))
if bhA > bhB:
return 1
elif bhA < bhB:
return 0
else:
return 'Are you kidding?'
#比较字符串
def comp_char(A,B):
charA = A.decode('utf-8')
charB = B.decode('utf-8')
n=min(len(charA),len(charB))
i=0
while i < n:
dd=comp_char_PY(charA[i],charB[i])
if dd == -1:
i=i+1
if i==n:
dd=len(charA)>len(charB)
else:
break
return dd
# 排序函数
def cnsort(nline):
n = len(nline)
lines='\n'.join(nline)
for i in range(1, n): #插入法
tmp = nline[i]
j = i
while j > 0 and comp_char(nline[j-1],tmp):
nline[j] = nline[j-1]
j -= 1
nline[j] = tmp
return nline
char=['赵','钱','孙','李','佘']
char=cnsort(char)
for item in char:
print item.decode('utf-8').encode('gb2312')
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有