30 Day code challenge-python

Day 28— Testing

Task

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.

Sample input and output

Input Format

The first line contains an integer, N, total number of rows in the table.
Each of the N subsequent lines contains 2 space-separated strings denoting a person’s first name and email ID, respectively.

Output Format

Print an alphabetically-ordered list of first names for every user with a gmail account. Each name must be printed on a new line.

Solution

Explanation

Line 1–5: Creates an empty list and gets the input from the user.

Line 7–13: Checks whether the input contains @gmail.com. If yes then the name is appended to the empty list.

Line 15–18: Prints the name in the sorted order.

Bonus Tip: We can sort and filter the special character only with the help of RegEx module. There’s no in build operation in python

See you on day 29

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store