I want the program to continue executing until every element on the list is a string.
That is
li = [1, 2, 6, 'h', 'y', 'h', 'y', 4]
should stop when
li = [all elements type are strings]
li = [1, 2, 6, 'h', 'y', 'h', 'y', 4]
while '''there are still numbers in the list''':
#code keeps on executing and updating li[] with string input
else:
# output the list with no numbers
This is what I have tried, but if the first[0] and and last[7] element becomes a string, the while loop goes to the last else condition even with int type present in the list. if done sequentially, it works fine.
li = [8, 2, 6, 'h', 'y', 'h', 'y', 4]
for a in li:
while a in li:
if type(a) == int:
x = int(input('Position: '))
entry = input('Enter: ')
li.pop(x)
li.insert(x, entry)
print(li) # to see what's happening
li = li
else:
print('Board is full')
print(li)
But, I don't want it sequentially.
Therefore, it should continue if
li = [c, 2, 6, 'h', 'y', 'h', 'y', f]
and stop when
li = [a, b, c, 'h', 'y', 'h', 'y', d]
all strings
You can use all or any in conjunction with string.isnumeric() to check this
li = ['a', 1, 2]
while any(str(ele).isnumeric() for ele in li):
modify li ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With