def numberSort():python
list1 = [] Flag = 10 while Flag: n = input('pelase input number:') Flag-=1 list1.append(n) list1.sort() return list1
print numberSort()app
def englishiIntoChinese():ide
word = raw_input('please input english word:')函數
with open('dictfile.txt', 'r') as f:設計
for i in f: if word==i.strip().split()[0]: return i.strip().split()[1] return '不存在!'
print englishiIntoChinese()code
字典的方法:排序
def englishiIntoChinese():ip
dict1 = {} # list1=[] word = raw_input('please input english word:') with open('dictfile.txt', 'r') as f: for i in f: if word in i: #dict1.setdefault(i.strip().split(0),i.strip().split(1)) #data = i.strip().split() dict1.setdefault(i.strip().split()[0],i.strip().split()[1]) break for k in dict1: if word ==k: print dict1[k]
englishiIntoChinese()utf-8
3,input
#!/usr/bin/env python
#-- coding:utf-8 --
word = raw_input('please input english word:')
with open('dictfile.txt', 'r') as f:
for i in f: if cmp(i[0], word[0]) == 1: print '不存在' break elif word == i.strip().split()[0]: print i.strip().split()[1] break else: continue