From a993e467c916955a609ee093da276bf57b19ec83 Mon Sep 17 00:00:00 2001 From: tiagorg Date: Mon, 31 Oct 2022 20:25:31 +0000 Subject: [PATCH] telephones.py -> telToName simplification Signed-off-by: tiagorg --- 1ano/fp/aula05/telephones.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/1ano/fp/aula05/telephones.py b/1ano/fp/aula05/telephones.py index d07b704..aeb8745 100644 --- a/1ano/fp/aula05/telephones.py +++ b/1ano/fp/aula05/telephones.py @@ -1,5 +1,3 @@ -from operator import contains - # Convert a telephone number into corresponding name, if on list. # (If not on list, just return the number itself.) @@ -7,14 +5,11 @@ from operator import contains def telToName(tel, telList, nameList): # your code here index = 0 - try: - for t in telList: - if t == tel: break - index += 1 - name = nameList[index] - except: - name = tel - return name + for t in telList: + if t == tel: + break + index += 1 + return tel if index == len(telList) else nameList[index] # Return list of telephone numbers corresponding to names containing partName. @@ -23,7 +18,7 @@ def nameToTels(partName, telList, nameList): tels = [] index = 0 for name in nameList: - if contains(name, partName): + if partName in name: tels.append(telList[index]) index += 1 return tels