22.11.05 Basic Data Structures - Dictionaries
Dictionaries - Lists와 함께 굉장히 많이 사용되는 데이터 구조 - 쓰앵님 말씀으로는 duck tape (강력 접착 테이프)과 WD-40 (윤활제)와 같은 존재들이라고... - curly bracket "{}" 안에 "key : value"로 정의되며 각 데이터는 trailing comma ","로 연결 >> animals = { #기본 정의 ... 'a':'aardvark', ... 'b':'bear', ... 'c':'cat' ...1 : 10, ...'50' : '55' ... } >>> animals {'a': 'aardvark', 'b': 'bear', 'c': 'cat', 1: 10, '50': '55'} >>> animals.keys() dict_keys(['a', 'b', '..
22.11.04 Basic Data Structures - Sets & Tuples
Sets - Declared with curly brackets "{}" >>> mySet = {'a','b','c'} >>> print(mySet) {'c', 'b', 'a'} >>> mySet {'c', 'b', 'a'} >>> mySet2 = set(['a','b']) >>> mySet2 {'b', 'a'} >>> mySet3 = set(('a', 'b')) >>> mySet3 {'b', 'a'} >>> mySet4 = set('a','b') Traceback (most recent call last): File "", line 1, in TypeError: set expected at most 1 argument, got 2 - All elements are unique >>> myList = [..
22.11.03 Basic Data Structures - Lists
Lists Slicing - ":"의 활용 방안 : 리스트 안에 저장된 데이터의 끝 (처음 또는 마지막)을 몰라도 ":"을 넣어버리면 된다. >>> myList = [1,2,3,4,5] >>> myList[3:] # : can indicate "until the edge" [4, 5] >>> myList[0:6:2] # 1st to 6th data in the gap of 2 [1, 3, 5] >>> myList[0:10:2] [1, 3, 5] >>> myList[0:6:3] [1, 4] >>> myList[:2:2] #1st to 2nd data in the gap of 2 [1] >>> myList[::2] #1st to last data in the gap of 2 [1, 3, 5] >>> myLi..