[英]how to remove commas and square brackets from my empty list?
好吧,我想要的是:
[1] [2] [3] [4]
我最終得到:
[[1]、[2]、[3]、[4]]
我做了 [我] 看看它是否會起作用,但我真的不知道,請幫助,我已經發送了完整的代碼讓你們看看發生了什么,並幫助我確切地知道它需要在哪里,因為我是python上的完整新手,我的朋友幫我做代碼但他也不知道
numeroIncorreto = True
continuaProcesso = True
lst_A = []
lst_B = []
while continuaProcesso:
while numeroIncorreto:
try:
n1 = int(input('Digite o primeiro número: '))
n2 = int(input('Digite o segundo número: '))
numeroIncorreto = False
except:
print('Favor digitar um número correto')
numeros = ''
if n2 >= 10 and n2 <= 50 and n1 >= 10 and n1 <= 50:
if n1>n2:
for i in range(n2, n1+1):
if i == n1:
numeros += str(i)
else:
numeros += str(i) + ' '
if i%2 == 0:
lst_A.append([i])
if str(i)[1] == '3' or str(i)[1] == '4': #
lst_B.append([i])
if n1<n2:
numeroD = n2
for i in range(n1, n2+1):
if numeroD == n1:
numeros += str(numeroD)
else:
numeros += str(numeroD) + ' '
if numeroD%2 == 0:
lst_A.append([numeroD])
if str(numeroD)[1] == '3' or str(numeroD)[1] == '4':
lst_B.append([numeroD])
numeroD -= 1
#Visualização na tela com devido espaço
print('\n'+numeros+'')
print('\nlst_A:')
print(lst_A)
print('\nlst_B:')
print(lst_B)
continuaProcesso = False
else:
print('Números fora do intervalo desejado.')
print('Numero 1: ' + str(n1))
print('Numero 2: ' + str(n2))
numeroIncorreto = True
嘗試print(*lst_A)
和print(*lst_B)
。
首先將列表中的元素轉換為字符串,然后連接元素
data = [[1], [2], [3], [4]]
data_str = [str(x) for x in data]
text = ' '.join(data_str)
print(text)
結果
[1] [2] [3] [4]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.