【发布时间】:2022-11-22 01:18:43
【问题描述】:
所以基本上我有很多点的列表,我只想提取唯一值。 我写了一个函数,但有 1 个问题:如何避免在列表末尾打印逗号?
def unique(list1):
unique_values = []
for u in list1:
if u not in unique_values:
unique_values.append(u)
for u in unique_values:
print(u, end=", ")
wells = ["U1", "U1", "U3", "U3", "U3", "U5", "U5", "U5", "U7", "U7", "U7", "U7", "U7", "U8", "U8"]
print("The unique values from list are...:", end=" ")
unique(wells)
我现在的输出是:“列表中的唯一值是……:U1、U3、U5、U7、U8,”
【问题讨论】:
标签: python