Code:
list1 = ['peter', 'james', 'code', 'key', 'jack']
list2 = ['flower', 'john', 'rose', 'red', 'green', 'peter']
f = any([item in list1 for item in list2])
output : ['Peter', 'james', 'code', 'key', 'jack']
when f its True, how can i replace list1 'peter' to 'Peter' when its False nothing to do
CodePudding user response:
as suggested you may just write
[item.title() if item in list1 else item for item in list2]
and obtain as output :
['flower', 'john', 'rose', 'red', 'green', 'Peter']