[英]I was stuck when I try to print first index in this function. I don't understand why the white spaces are printed together
下面有代码,我必须解决最底部的打印错误。
我检查了很多有关此错误的信息,但即使现在我也找不到。
如何删除位于列表索引旁边的空格? 这是示例,我想更改此方法
def arithmetic_arranger(problems,display=False):
operators = []
list1 = []
list2 = []
new_list1=[]
new_list2=[]
for problem in range(len(problems)):
if '+' in problems[problem] or '-' in problems[problem]:
problems[problem] = problems[problem].split(' ')
list1.append(problems[problem][0])
operators.append(problems[problem][1])
list2.append(problems[problem][2])
for problem in range(len(problems)):
width = max(len(list1[problem]),len(list2[problem]))+2
new_list1.append(' '*(width-len(list1[problem]))+list1[problem])
print(list1)
print(new_list1)
print(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"]))
new_list1.append(' ' * (width - len(list1[problem])) + list1[problem])
使用这部分代码append(' ' * (你是在告诉程序向每个列表元素附加一些空格,这些空格等于宽度减去 list1[问题] 的长度......我不认为你可以取消列表元素之间的空格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.