Python Day 28: RegEx, Patterns, and Intro to Databases




Consider a database table, Emails, which has the attributes First Name and Email ID. Given N rows of data simulating the Emails table, print an alphabetically-ordered list of people whose email address ends in @gmail.com.



  1. #!/bin/python3
  2. import re
  3. if __name__ == '__main__':
  4. N = int(input())
  5. pattern = r"@gmail\.com$"
  6. regex = re.compile(pattern)
  7. firstNames = []
  8. for N_itr in range(N):
  9. firstNameEmailID = input().split()
  10. firstName = firstNameEmailID[0]
  11. emailID = firstNameEmailID[1]
  12. if regex.search(emailID):
  13. firstNames.append(firstName)
  14. firstNames.sort()
  15. for name in firstNames:
  16. print(name)




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube