Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #Find all of the instances of non alphanumeric characters in 'lorem_ipsum'
  2. #Output the number of non-alphanumeric characters.
  3.  
  4. results= re.findall(r'[^a-zA-Z0-9]',lorem_ipsum)
  5. print(len(results))
  6.  
  7. #Find all of the instances of 'sit-amet' or 'sit:amet' characters in 'lorem_ipsum'
  8. #Set variable named 'occurrance_sit_amet'
  9. #Output the number of sit-amet or sit:amet occurrances.
  10.  
  11. occurrences_sit_amet= re.findall(r'sit[-:]amet',lorem_ipsum)
  12. print(len(occurrences_sit_amet))
  13.  
  14. #Replace sit:amet and sit-amet with sit amet using.
  15. #Set variable named 'replace_results'
  16.  
  17. replace_results = re.sub('sit[:-]amet','sit amet', lorem_ipsum )
  18.  
  19. #Find all of the instances of 'sit amet' in 'replace_results'
  20. #Set a variable named 'occurrance_sit_amet'
  21. #Output the number of sit amet occurrances.
  22.  
  23. occurrences_sit_amet= re.findall('sit amet',replace_results)
  24. print(len(occurrences_sit_amet))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement