From 1c2f80684e60e5f93eff8d545efe9fae2ebfea6e Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Mon, 28 Nov 2022 18:01:03 +0000 Subject: [PATCH] Converted names.py to a list comprehension --- 1ano/fp/aula08/names.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/1ano/fp/aula08/names.py b/1ano/fp/aula08/names.py index a5f66f5..469fd2d 100644 --- a/1ano/fp/aula08/names.py +++ b/1ano/fp/aula08/names.py @@ -1,12 +1,9 @@ def main(): with open('names.txt', 'r') as f: names = f.read().split('\n') - surnames = set([name.split(' ')[-1] for name in names[1:]]) - namesDict = {} - for surname in surnames: - namesDict[surname] = set([name.split(' ')[0] for name in names[1:] if surname in name and surname != '']) + namesDict = {surname: set([name.split(' ')[0] for name in names[1:] if surname in name]) + for surname in set([name.split(' ')[-1] for name in names[1:] if name != ''])} - del namesDict[''] printNames(namesDict)