-
[Python] 파이썬 count 함수 정리하기
count 함수 정의 count함수는 주어진 리스트(or 문자열)에서 특정 원소가 몇 개 있는지 알려주는 함수입니다. count힘수는 주로 문자열에서 많이 쓰입니다. ※count 함수는 문자열,리스트,튜플을 인자로 받을 수 있습니다.(딕셔너리,집합 제외) count 함수 용도 count함수는 문자열 속 특정 문자의 개수를 구할 때 사용합니다. count함수는 리스트,튜플 속 특정 원소의 개수를 구할 때 사용합니다. count 함수 사용법 “문자열”.count(“특정문자”) “리스트”.count(“특정원소”) count 함수 예시 예시1: 문자열에서 특정 문자 개수 name = "skytink1004" p... Read More
-
[Python] 파이썬 enumerate 함수 정리하기
enumerate 함수 정의 enumerate 는 리스트의 원소와 번호를 차례대로 나열하는 함수입니다. ※enumerate 는 ‘나열하다’ 라는 뜻입니다. ※enumerate 는 리스트 뿐만 아니라 반복가능한 객체인 [list,tuple,set,dictionary,string]에 적용할 수 있습니다. enumerate 함수 용도 enumerate함수는 리스트 원소들에 번호를 매길 때 사용합니다. enumerate 함수 사용법 : enumerate(리스트,start = 시작번호) enumerate 의 첫번 째 인자에는 번호를 매길 리스트가 들어가고 두 번째 인자에는 원소에 번호가 매겨지는 시작번호가 들어갑... Read More
-
[Python] deque 정리하기
deque(double-ended-que) deque는 리스트 처럼 원소들을 담아둘 수 있는 자료구조이며 리스트와는 다르게 큐의 양 옆에서 원소를 삽입하거나, 지울 수 있습니다. 기존의 리스트를 이용할 때는 원소들을 순환(rotate) 시키거나 리스트 가장 앞에 원소를 추가시키려면 직접 코드로 구현해야 하지만 deque 를 이용하면 deque 원소들을 순환(rotate)시키거나 deque 가장 앞에 원소를 추가시키는 등 기존 리스트에서는 하기 어려웠던 다양한 기능들을 활용할 수 있습니다. 이번 포스트에서는 deque 메소드의 여러가지 사용법을 정리하겠습니다. deque 의 용도 deque 자료구조는 리스트로는... Read More
-
[Python] 리스트 중복 제거
파이썬 리스트 중복 제거하는 방법 파이썬에서 중복을 제거하는 방법은 크게 세가지가 있습니다. 집합(set)을 이용해서 중복 제거하기 for문 이용해서 중복 제거하기 dict.fromkeys() 이용해서 중복 제거하기 예시1: 집합(set)을 이용해서 중복 제거하기 ex1 = "hello!" ex2 =[1,0,0,4] print(list(set(ex1))) print(list(set(ex2))) 실행결과 ['h', 'l', 'e', '!', 'o'] [0, 1, 4] 집합을 이용해서 중복된 원소를 제거하면 리스트의 순서가 뒤섞이는 것을 알 수 있습니다. 기존 리스트의 순서를 보존하면... Read More
-
[Python] 파이썬 split 함수 정리하기
split함수 정의 split 함수는 문자열을 쪼개서 리스트로 만드는 함수입니다. split 함수 사용법 “문자열”.split() (띄어쓰기 기준으로 문자열 쪼개기) (ex.”Hello my name is skytin1004”.split()) “문자열”.split(“구분자”) (구분자 기준으로 문자열 쪼개기) (ex.”Hello_my_name_is_skytin1004”.split(“_”)) “문자열”.split(“구분자”,분할횟수) (분활횟수 만큼 구분자 기준으로 문자열 쪼개기) (ex.”H... Read More