uaveiro-leci/1ano/fp/aula08/names.py

17 lines
465 B
Python
Raw Normal View History

2022-11-18 10:45:54 +00:00
def main():
with open('names.txt', 'r') as f:
names = f.read().split('\n')
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 != ''])}
2022-11-18 10:45:54 +00:00
printNames(namesDict)
def printNames(namesDict):
for surname in namesDict:
print(f"{surname} : {namesDict[surname]}")
if __name__ == "__main__":
main()