简体   繁体   中英

How to remove brackets '[]' and comma from my output result?

My Python program is:

def remove(duplicate):
  final_list=[]
  for num in duplicate:
    if num not in final_list:
      final_list.append(num)
  return final_list
duplicate=input()
print(remove(duplicate),end="")

It's simple, you are printing the entire list, wich output is the [] and the commas. You just have to print each element separately Like:

for elem in remove(duplicate):
      print(elem, end=" ")

您可以使用str.join将列表转换为以空格分隔的字符串作为输出:

print(' '.join(remove(duplicate)),end="")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM