我不断收到TypeError:只能加入一个迭代。 我想从Python中的字符串中删除特定的字符。问题在删除字符串中的特定字符
def get_2s_and_5s_removed(dice_string):
dice_string =list(dice_string)
if '2' in dice_string:
dice_string =dice_string.remove('2')
return ''.join(dice_string)
if '5' in dice_string:
dice_string =dice_string.remove('5')
return ''.join(dice_string)**
是否要删除*所有* 2秒和5秒顾名思义?你的算法,如果它的工作,将删除一个2 else one 5. –
然后我应该添加一个while循环和一个坏的声明 – Adrian