python/리스트
중복 안 된 숫자 제거
june__Park
2021. 3. 1. 01:01
# 중복안된 숫자 제거
test1 = [1, 2, 3, 2, 1]
test2 = [1, 3, 4, 4, 2]
test3 = [1, 1, 1, 2, 1]
# 위 리스트에서 중복 안된 숫자를 제거하시오.
# [1] [1, 2, 2, 1]
# [2] [4, 4]
# [3] [1, 1, 1, 1]
temp1 = []
temp2 = []
temp3 = []
i = 0
while i < 5:
cnt = 0
j = 0
while j < 5:
if i != j and test1[i] == test1[j]:
cnt = 1
j += 1
if cnt == 1:
temp1.append(test1[i])
cnt = 0
j = 0
while j < 5:
if i != j and test2[i] == test2[j]:
cnt = 1
j += 1
if cnt == 1:
temp2.append(test2[i])
cnt = 0
j = 0
while j < 5:
if i != j and test3[i] == test3[j]:
cnt = 1
j += 1
if cnt == 1:
temp3.append(test3[i])
i += 1
print(temp1)
print(temp2)
print(temp3)