Advertisement
Cobble5tone

Educational - Using replace when iterating through list

Aug 28th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. a2 = 'Hello my name is sofiene'
  2. b2 = ['Hello', 'is']
  3.  
  4. for item in b2:  # Iterates through words in b2 using 'item' at iterator
  5.     replace_words2 = a2.replace(item, '')  # searches string for each word and replaces it with nothing
  6.     a2 = replace_words2 # Redefines a2 after being modified with replace
  7.  
  8. print(a2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement