首页 > 代码库 > 用户排序
用户排序
#给输入的用户按照首字母排序# #!/usr/bin/env python #coding:utf-8 ‘‘‘ Program: Sort and output by name History: 2017.03.29 Mr.liu First release ‘‘‘ ‘‘‘ total = input("the total number of name:") li = [] errcount = 0 count = 0 while count < total: name = raw_input("Please input %d name(s): \n" % (4 - count)) if "," in name: li.append(name) count += 1 else: errcount += 1 print "ERROR:%d time(s) bad input:‘,‘ \n Please try agin." %(errcount) li = sorted(li) dic = {}.fromkeys(li) print "The sorted list by first name is:" for d in dic.keys(): print d ‘‘‘ count = input("Enter total munber of name:") li = [] errCount = 0 i = 0 while i < count: name = raw_input("Please input your name:") if "," in name and "," != name[0] and name.index(",") != len(name) - 1 and name.count(",") == 1: li.append(name) i += 1 else: errCount += 1 print "ERROR:%d time(s) bad input:‘,‘ Please try agin." %(errCount) else: li = sorted(li) print "The sorted list by first name is:" for i in li: print i
本文出自 “12449513” 博客,请务必保留此出处http://12459513.blog.51cto.com/12449513/1912420
用户排序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。