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 odpowiedzi
+ 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