mardi 28 juin 2016

How to properly build a dictionary when .txt file has the key and values on pairs of consecutive lines?


Code:

trans_file = open("textabbv.txt", "r")
def text_translate(user_input):
    user_input = input("Please enter your text: ")  
    textdict = {}
    for line in trans_file:
        readline(line)
        line = line.split(":")
        line = line.strip('n')

Contents of textabbv.txt:

r:
are
y:
why
u:
you
ttyl:
talk to you later
l8:
late
brb:
be right back
lol:
laughing out loud
bbl:
be back later
tl;dr:
too long; didn't read
rofl:
rolling on floor laughing
gtg:
got to go
cya:
see you
cuzz:
because
bff:
best friend forever
bffs:
best friends forever
idk:
I don't know
sup:
what's up?
omg:
oh my gosh
nbd:
no big deal
tisnf:
this is not fair
nw:
no way!
rus:
are you serious?
myob:
mind your own business
njoy:
enjoy
nter:
enter
1ce:
once
aka:
also known as
afk:
away from keyboard
jk:
just kidding
asap:
as soon as possible
app:
application
atm:
at the moment
b4:
before
fyi:
for your information
bday:
birthday
k:
okay
msg:
message
np:
no problem
pic:
picture
plz:
please
sry: sorry
dunno:
don't know
@:
at
wut:
what
wuts:
what's


Aucun commentaire:

Enregistrer un commentaire