LearnPy Hub
← Regular Expressions problems
Medium

Parse a Record With Named Groups

Each line looks like Name: Mim, Age: 15, City: Dhaka. Use a pattern with named groups (?P<name>…) to print NAME (AGE) from CITY, or bad record if the line does not match.

Input

n, then n lines.

Output

n lines.

Sample 1

Input
2
Name: Mim, Age: 15, City: Dhaka
Name: Rafi, Age: x, City: Sylhet
Output
Mim (15) from Dhaka
bad record

Sample 2

Input
1
Name: Sara Khan, Age: 30, City: Cox Bazar
Output
Sara Khan (30) from Cox Bazar
solution.py
Output appears here
Parse a Record With Named Groups · Python practice problem · LearnPy Hub