我希望程序能够继续执行,直到列表中的每个元素都是字符串。
li = [1, 2, 6, 'h', 'y', 'h', 'y', 4]
应该在以下情况停止:
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
这是我尝试过的,但如果
first[0]
和last[7]
元素变成字符串,即使在列表中有int
类型,while循环也会进入最后一个else条件。 如果按顺序完成,则可以正常工作。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)
但是,我不想按顺序进行。
因此,如果遇到
li = [c, 2, 6, 'h', 'y', 'h', 'y', f]
并在...时停止
li = [a, b, c, 'h', 'y', 'h', 'y', d]
所有字符串