for homework I need to create a function that receives 2 list of numbers and every time a number from the first list matches with one of the second one I have to add 10 to the number in the first list. Here's what I've tried.
def modifyEspecials(mylist,especials):
return list(map(lambda n: str(int(n)+10) if map(lambda x: True if n==x else False,especials)== True else n,mylist))
if __name__ == "__main__":
especials=[*range(39,48),*range(58,63),*range(91,97)]
mylist= ['72', '45', '41', '56', '46', '56', '49', '45', '48', '41', '39', '46', '71', '52', '46', '56', '52', '46', '42']
modifiedList= modifyEspecials(mylist,especials)
print(modifiedList)
This returns the same list.
Note: I can't create variables inside modifyEspecials() in this homework and I'm only allowed to import ascii_lowercase, ascii_uppercase and functools or for/while loops
mylistis a list of strings, not numbers.mylistis all strings, it's not the same length asespecials, it's unclear if you need to add 10 when two values in matching positions are the same, or only if a value from the first is in the second list at all. Your function body is very complicated, but does the same asreturn list(map(lambda n: str(int(n)+10) if False else n, mylist)), so it's the same asreturn list(map(lambda n: n, mylist))or reallyreturn list(mylist)- and that's what it does.