我有这个:
LOL, laugh out loud
ROLF, rolling on the floor laughing
ACE, a cool experience
AD, awesome dude
AFAIR, as far as I remember
AFK, away from keyboard
ANI, age not important
CUL, see you later
CWYL, chat with you later
IQ, ignorance quotient
BA, Bachelor of Arts
BS, Bachelor of Science
MA, Master of Arts
JD, Juris Doctor
DC, Doctor of Chiropractic
PA, Personal Assistant
MD, Managing Director
VP, Vice President
SVP, Senior Vice President
EVP, Executive Vice President
CMO, Chief Marketing Officer
CFO, Chief Financial Officer
CEO, Chief Executive Officer
这是加载的文本文件的内容:
#import <UIKit/UIKit.h>
#include "secondViewController.h"
@interface ViewController : UIViewController<ConverterDelegate>
@property (strong,nonatomic) secondViewController *secondview;
@property (strong, nonatomic) IBOutlet UILabel *msgtext;
@property (strong, nonatomic) IBOutlet UIButton *converbutton;
@end
我刚刚完成了几分钟前它工作正常但我觉得这不是这样做的方式,不是吗?我只是对某些人的意见感到好奇。据说,如果它有效,那么没关系,但我认为在这种情况下我不能说这个。所以你怎么看?感谢...
答案 0 :(得分:2)
您最好先将文件读入字典:
abbrevs = {}
with open('abbreviations.txt') as f:
for line in f:
short, long = line.rstrip().split(',', 1)
abbrevs[short] = long
然后,您可以通过字典中的简单查找找到缩写:
v_word = str(raw_input('Abbreviation ? '))
if v_word not in abbrevs:
print "Don't know what that means."
else:
print "{} means {}".format(v_word, abbrevs[v_word])
答案 1 :(得分:0)
d = dict()
d['LOL'] = [5,19]
d['ROLF']= [26,55]
// other indexes
while v_exit != 'no':
v_word = str(raw_input('Abbreviation ? '))
print '%sL means: %s', % (v_word, (v_abbrv[d[v_word][0], d[v_word][1]]))
答案 2 :(得分:0)
通过以下方式将文件行读入字典:
希望这有帮助。
v_file = open('abbreviations.txt','r')
v_dict = {}
v_word = raw_input('Enter an abbreviation: ')
# add abbreviations and meanings to a dictionary
for line in v_file.readlines():
a, b = line.split(', ')
v_dict[a] = b.rstrip()
# lookup meanings of abbreviations
if v_word in v_dict:
print(v_dict[v_word])