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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -