| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
- JS
- db
- regExp
- File
- SQL
- css
- regex
- JavaScript
- Git
- key
- STS
- Windows
- table
- jsp
- PostgreSQL
- jQuery
- Python
- html
- spring
- lambda
- Session
- list
- dict
- Oracle
- MAP
- JSON
- Linux
- port
- Java
- insert
- Today
- Total
목록dict (4)
step1
*len 99999 list 로 테스트시 소요 시간(microseconds) 1. using collections.Counter() import collections def getFreqByCollections(org_list): return collections.Counter(org_list) ⇒ 2735 microseconds 2. make it as a set → count def getFreqByCount(org_list): return {x:org_list.count(x) for x in set(org_list)} ⇒ 4987 microseconds 3. using itertools.groupby() from itertools import groupby def getFreqByGroupby(or..
검색하는 key 가 없을 때, mydict = {"hello" : "world"} get() : None result = mydict.get("world")#None [] => KeyError result = mydict["world"]#KeyError
Shallow copy : 주소값을 복사하기 때문에 하나를 바꾸면 다른 애도 바뀜. Deep copy : 내용을 복사해서 새로 생성 => mutable 한 list, set, dict 를 복사해서 쓰려면 deep copy.deepcopy() 해야 됨! * json data를 복사할 때도 마찬가지! deep copy 해서 비교하기 import json import copy json_file = "C:/~" with open(json_file, "r", encoding='utf-8') as j: json_data = json.load(j) copied = copy.deepcopy(json_data)
리스트에 중복되는 원소가 있을 때, 각 원소가 몇 개씩 있는지 → {"원소" : "개수} collections.Counter 사용! → 결과는 dict 형식 , value 순으로 정렬돼서 저장! import collections hello = "hello" hello_list = list(hello) counted_dict = collections.Counter(hello_list) counted_dict Counter({'l': 2, 'h': 1, 'e': 1, 'o': 1}) type : collections.Counter 원하는 원소의 개수 확인 counted_dict["h"] key 값 종류 확인 : keys() counted_dict.keys() dict_keys(['h', 'e', 'l', '..