컴퓨터_Com/파이썬 초급 연습문제_Exercise for bigginers
[파이썬 초급 연습문제 #14] 함수 이용하기 (Fibonacci)
bhjo
2019. 8. 27. 17:23
Exercise 14: 리스트를 받아서 중복되는 숫자를 지워서 새로운 리스트를 만드는 프로그램(함수 이용)을 만들어라.
추가 : 하나는 loop를 이용하고 다른 하나는 set()을 이용하라.
Sets의 특징
- Sets의 구성요소들은 순서가 없이 나열된다.
- Sets의 구성요소들은 중복되지 않는다. (set()을 이용하면 중복된 숫자를 지우는 것이 가능하다.)
- Sets와 리스트를 변경하는 것이 매우 쉽다.
In Python
1
2
3
4
5
6
7
8
9
10
11
12
|
names = set()
names.add("Michele")
names.add("Robin")
names.add("Michele")
print(names)
{'Michele', 'Robin'}
names = ["Michele", "Robin", "Sara", "Michele"]
names = set(names)
names = list(names)
print(names)
['Sara', 'Michele', 'Robin']
|
cs |
내 풀이
14_listRemoveDuplicates_for.py
0.00MB
14_listRemoveDuplicates_set.py
0.00MB