replacing values from file python -
if file contains 2 b 3 , have replace user input if contains or b values 2 , 3, (example: banana should turn 2 banana) far have done this:
word=input("enter string: ") word=list(word) open('mapping.txt') f: key = {} line in f: first, second = line.split() key[first] = second in word: if first in i: word=word.replace(i,key[i])
but not change nott prints, u kindly me
i think should work:
#!/usr/local/bin/python3 word=input("enter string: ") open('input.txt') f: key = {} line in f: first, second = line.split() key[first] = second replacement in key: word=word.replace(replacement,key[replacement]) print(word)
Comments
Post a Comment