Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Mar 22 20:00:53 2019
  4.  
  5. @author: Matth
  6. """
  7.  
  8. import re
  9. def urgent_emails(emails):
  10.  
  11. urgentRegex = re.compile('urgent')
  12. list = []
  13.  
  14. ## loop through every email in email list
  15. for i in emails:
  16.  
  17. ## construct variable that has string "urgent" if value belonging to key 'subject' contains UrGent
  18. variable = urgentRegex.search(
  19. (i['subject']).lower())
  20.  
  21. ## check if variable is equal to urgent
  22. if variable.group()=='urgent':
  23. list.append(i['author'])
  24. return list
  25.  
  26. emails1 = [
  27. {
  28. 'author': 'emil@booking.com',
  29. 'subject': 'Urgent: you better do your homework!',
  30. 'content': 'New session is coming, please get the homework ready so we can do amazing stuff!'
  31. },
  32. {
  33. 'author': 'kerem@booking.com',
  34. 'subject': 'News',
  35. 'content': 'I am going to take over Emil\'s class next week. Be sure to be there!'
  36. },
  37. {
  38. 'author': 'staff@booking.com',
  39. 'subject': 'URGENT - change your password now!',
  40. 'content': 'Your password has expired, change your password now!!!'
  41. },
  42. {
  43. 'author': 'workbook@booking.com',
  44. 'subject': '[EXTERNAL]Whatever news have been posted...',
  45. 'content': 'X has done Y Urgent thing on platform Z, hooray!'
  46. }
  47. ]
  48.  
  49. urgent_emails(emails1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement