본문 바로가기

Programming

(38)
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..
22.10.31 Challenge_Directional Terminal Scribe(3) 헤 헤 헤 나만의 방식으로 challenge에 성공하였다. 아침에 샤워하는데 퍼뜩 생각이 나서 오늘 퇴근하고 코드를 작성해 보았다. 원하는 대로 동작한다! 감격! 🌈MY OWN SOLUTION 최초에 들었던 생각대로, round()를 이용할 것이다. 최종 목적지는 주어진 반지름 (canvas의 attribute), 주어진 degree (scribe.setDegrees의 attribue)를 삼각함수로 계산했을 때 산출되는 x, y 좌표값이 되겠다! 예를 들어, 반지름 30에 145 deg일 경우 최종 목적지는 (30*sqrt(2)/2, 30*sqrt(2)/2). 그 지점까지의 직선을 따라 (1*sqrt(2)/2, 1*sqrt(2)/2), (2*sqrt(2)/2, 2*sqrt(2)/2), (3*sqrt(2)..
22.10.30 Challenge_Directional Terminal Scribe(2) 자, 지난 이틀은 취미 다이빙 일정으로 참석이 어려웠다. 다시 열심히 해보자! 내가 재능이 없다는 생각에 포기하고 싶다는 생각이 드는데... 학교 다닐 때부터 그런 생각 많이 하지 않았니? 그리고 많이 포기했었지 않았니? 그 때 너가 얻은 takeaway는 뭐였니? 하다가 그만두는 것은 결국 아무것도 하지 않은 것이라는 결론이 나지 않았니? 하다가 그만두지 않고 그 끝을 본 적이 네 인생에 있었니? 이번에는 아무 생각없이 조금씩 쌓아가서 그 끝을 한 번 봐보자! Challenge! Directional Terminal Scribe - Add a direction attribute that can be passed into the constructor to know which way it's pointin..
22.10.27 Challenge_Directional Terminal Scribe Challenge! Directional Terminal Scribe - Add a direction attribute that can be passed into the constructor to know which way it's pointing - Then create a function "forward" that moves it in the direction - You can use math library to get a direction vector based on coordinate (x, y) 기존 Terminal Scribe에서 완성했던 사각형을 다 그리고, attribute 로 입력받은 lists 타입의 데이터가 말하는 좌표로 곧바로 노란 점이 이동! 아래와 같이 TerminalScribe..
22.10.26 Basic Data Types(3) Python Bytes Objects - A sequence of data (random 0 or 1) - Common behind the scenes - Used as data that gets passed in a program - Rarely manipulated or modified directly - Immutable like tuples (to modify, you need to use "bytearray" - Common Uses : Streaming files, Transmitting text without knowing the encoding, Often used "under the hood" in Python libraries #byte object의 생성 >>> bytes(4) #cr..
22.10.25 Basic Data Types(2) Slicing strings 타입이든, Lists 타입이든, 모든 데이터 타입은 bracket []을 이용해 분해 가능하다. #strings name = 'My name is Ella Kim' name[0] #return 'M' name[1] #return 'y' name[2] #return ' ' name[0:7] #return 'My name' name[:7] #return 'My name' name[11:] #return 'Ella Kim' len(name) #return 18 #lists myList = [1,2,3,4,5] myList[2:4] #return [3,4] len(myList) #return 5 Formatting Python은 string formatting이 용이한 편이다. f'..