Two lines needlessly used in else statement. Help shorten it | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
0

Two lines needlessly used in else statement. Help shorten it

#verifying my shopping list i=input() shopping=['tomato', 'potato', 'onion'] j=2 if i in shopping: print('its there') #remove duplication in next two line else: shopping+=[j+1] shopping [j+1]=i print(shopping)

21st Oct 2017, 1:41 PM
a2warik
a2warik - avatar
2 ответов
+ 8
#you can do this: shopping.append(i) #however, that's asuuming you don't want shopping+=[j+1] , I don't know why you'd want to add the number three to it...
21st Oct 2017, 2:45 PM
Ahri Fox
Ahri Fox - avatar
+ 1
thank you, I seem to have forgotten why I couldn't think of append or insert commant
5th Nov 2017, 2:49 PM
a2warik
a2warik - avatar