unique 요소만 포함하는 set

특정 집합을 만들다보니 같은 값이 저장되지 않는 리스트를 만들 필요가 생겼다.
set() 형식을 사용하면 unique한 객체만 포함하는 집합을 만들 수 있다.

단, 사용하려면 set()으로 객체를 초기화 해야한다.

1
2
set = set([1,1,1,1,2,3,10,10,31])
print(set)
{1, 2, 3, 10, 31}

dictionary와 동일한 {, }로 사용되지만 dictionary와 다르게 key가 없는 list 형식이다.

외부링크

Author

Hangack

Posted on

2022-02-07

Updated on

2022-02-17

Licensed under

댓글