I am trying to make a plan that allows you to insert strings to a list until you type a certain keyword which then locks the list from further appending.
print("I will list everything you desire!")
list = []
while(input("")!="stop"):
shop_list = [list.append(i) for i in input("")]
print(shop_list)
list.clear()
yet once I run this program I get an output, that has a few issues.
output:
[None,None] (amount of None is per the number of inputs you give)
In addition to this, after the program finishes running I don’t seem to get list cleared. I don’t understand why, considering that the clear function should do just as I intend.
regarding the first problem, I assume it is due to incorrect use of input("") in the extent of list comprehension.
and with the latter issue, I suppose I might have used clear function incorrectly. although this is how I should use it.
>Solution :
You prob. can try this, as earlier comment pointed out your syntax is off… so it needs to be rewrite and corrected:
print("I will list everything you desire!")
# L = []
shop_list = []
while True: # Loop continuously
item = input() # get the input - one item at a time (one line)
if item != 'stop': # not done yet....
shop_list.append(item)
else:
break
print(f' the shop list: {shop_list}')
shop_list.clear()
# Outputs Example: assuming typing each word by itself (one line each word)
# the shop list: ['apple ', 'orange', 'banana ']