-1
How to resolve this with regex?
The archive
assets/grades.txt
contains a list of people - one per line - containing your notes. Create a regex to generate a list of students who received grade B.
Filing cabinet assets/grades.txt
:
Ronald Mayr: A
Bell Kassulke: B
Jacqueline Rupp: A
Alexander Zeller: C
Valentina Denk: C
Simon Loidl: B
Elias Jovanovic: B
Stefanie Weninger: A
Fabian Peer: C
Hakim Botros: B
Emilie Lorentsen: B
Herman Karlsen: C
Nathalie Delacruz: C
Casey Hartman: C
Lily Walker : A
Gerard Wang: C
Tony Mcdowell: C
Jake Wood: B
Fatemeh Akhtar: B
Kim Weston: B
Nicholas Beatty: A
Kirsten Williams: C
Vaishali Surana: C
Coby Mccormack: C
Yasmin Dar: B
Romy Donnelly: A
Viswamitra Upandhye: B
Kendrick Hilpert: A
Killian Kaufman: B
Elwood Page: B
Mukti Patel: A
Emily Lesch: C
Elodie Booker: B
Jedd Kim: A
Annabel Davies: A
Adnan Chen: B
Jonathan Berg: C
Hank Spinka: B
Agnes Schneider: C
Kimberly Green: A
Lola-Rose Coates: C
Rose Christiansen: C
Shirley Hintz: C
Hannah Bayer: B
My attempt:
import re
def grades():
with open ("assets/grades.txt", "r") as file:
grades = file.read()
#print(grades)
# YOUR CODE HERE
B_entities = re.finditer("(?P<name>[\w ]*):\s(?P<grade>B$)", grades)
counter = 0
for item in B_entities:
print(item.groupdict(['name']))
counter += 1
print(counter)
return B_entities
grades()
Opa, this community is in Portuguese. I recommend editing the translated question and including the code example you tried, as it is also part of the question.
– Jorge Mendes