telephones.py -> telToName simplification
Signed-off-by: tiagorg <tiagorg@rendlaptop>
This commit is contained in:
parent
a4900b7585
commit
f16aea51d1
|
@ -1,5 +1,3 @@
|
||||||
from operator import contains
|
|
||||||
|
|
||||||
# Convert a telephone number into corresponding name, if on list.
|
# Convert a telephone number into corresponding name, if on list.
|
||||||
# (If not on list, just return the number itself.)
|
# (If not on list, just return the number itself.)
|
||||||
|
|
||||||
|
@ -7,14 +5,11 @@ from operator import contains
|
||||||
def telToName(tel, telList, nameList):
|
def telToName(tel, telList, nameList):
|
||||||
# your code here
|
# your code here
|
||||||
index = 0
|
index = 0
|
||||||
try:
|
for t in telList:
|
||||||
for t in telList:
|
if t == tel:
|
||||||
if t == tel: break
|
break
|
||||||
index += 1
|
index += 1
|
||||||
name = nameList[index]
|
return tel if index == len(telList) else nameList[index]
|
||||||
except:
|
|
||||||
name = tel
|
|
||||||
return name
|
|
||||||
|
|
||||||
|
|
||||||
# Return list of telephone numbers corresponding to names containing partName.
|
# Return list of telephone numbers corresponding to names containing partName.
|
||||||
|
@ -23,7 +18,7 @@ def nameToTels(partName, telList, nameList):
|
||||||
tels = []
|
tels = []
|
||||||
index = 0
|
index = 0
|
||||||
for name in nameList:
|
for name in nameList:
|
||||||
if contains(name, partName):
|
if partName in name:
|
||||||
tels.append(telList[index])
|
tels.append(telList[index])
|
||||||
index += 1
|
index += 1
|
||||||
return tels
|
return tels
|
||||||
|
|
Loading…
Reference in New Issue