#!/usr/bin/env python #coding:utf-8 ‘‘‘ Program: sorted the name inputed and output by number History: 2017.03.29 Mr.liu First release ‘‘‘ li = [] count = 0 while count < 100: print "Up to 100 employees information input,and %d employee(s) already input.\n(Please input ‘ending‘ if input finish) )" %(count) name = raw_input(" Please input the message of employees(like: name,number):") if "," in name and "," != name[0] and name.index(",") != len(name) - 1 and name.count(",") == 1: li.append(name) count += 1 elif name == "ending": break else: name =raw_input("Unknown message! Please try again:") li.append(name) count += 1 else: li = sorted(li) print "Employee information sheet is as follows (sorted by name):" for i in li: print i li = sorted(li, key=lambda d : int(d.split(‘,‘)[-1])) print "Employee information sheet is as follows (sorted by number):" for i in li: print i
时间: 2024-10-10 18:22:28