runtime
124 / 500
question 124 Comprehensions · easy

Rows that fail the import check

Before importing a user list, report the rows that would break it, so someone can fix them by hand. A row is invalid when its email does not contain exactly one @, or contains a space, or when its age is not a whole number written with digits only.

Functioninvalid_rows(rows)
rowsa list of dictionaries with text fields "user_id", "email" and "age"
Returnsthe user_id of every invalid row, in the order the rows appear; [] when all rows are valid
Rulesan empty age is invalid; a negative age such as "-3" is invalid (the minus is not a digit)
Examples
callinvalid_rows([{'user_id': 'U01', 'email': 'nora@fastmail.com', 'age': '34'}, {'user_id': 'U02', 'email': 'jamal.walker62icloud.com', 'age': '29'}, {'user_id': 'U03', 'email': 'grace_walker29@yahoo.com', 'age': ''}, {'user_id': 'U04', 'email': 'theo@@gmail.com', 'age': '41'}])returns['U02', 'U03', 'U04']
callinvalid_rows([{'user_id': 'U09', 'email': 'ana@x.org', 'age': '18'}])returns[]
callinvalid_rows([])returns[]

Loading your progress…

Rows that fail the import check — Python practice · Runtime