[Python] json의 key, value에 따른 데이터 추출
json에서 key값이 실제 값인 경우 user_list = { "user1": { "key1" : "Y", "key2" : "Y" }, "user2": { "key1" : "N", "key2" : "Y" }, "user3": { "key1" : "N", "key2" : "N" } } key만 필요한 경우 list = data.keys() # dict_keys(["user1","user2","user3"]) list = [user for user in data] # ["user1","user2","user3"] value만 필요한 경우 list = [data.get(user) for user in data] ''' [ { "key1" : "Y", "key2" : "Y" }, { "key1" : "N", ..
2023. 3. 10.
[Python] String에 변수 사용(f-string)
기존 python에서는 string에 변수를 넣기 위해서는 C와 유사한 아래와 같은 형식이나, str = "Hello, World, My name is %s, I'm %d years old" % (name, age) format()을 사용하여 변수를 매핑하여 사용하였다. str = "Hello, World, My name is {}, I'm {} years old".format(name, age) Python 3.6부터 f-string을 지원하여 이를 사용 가능하다. str = f"Hello, World, My name is {name}, I'm {age} years old"
2022. 11. 13.
[LeetCode] 83. Remove Duplicates from Sorted List
Given the head of a sorted linked list, delete all duplicates such that each element appears only once. Return the linked list sorted as well. Example 1: Input: head = [1,1,2] Output: [1,2] Example 2: Input: head = [1,1,2,3,3] Output: [1,2,3] Constraints: The number of nodes in the list is in the range [0, 300]. -100
2022. 10. 27.
[LeetCode] 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path. Note: You can only move either down or right at any point in time. Example 1: Input: grid = [[1,3,1],[1,5,1],[4,2,1]] Output: 7 Explanation: Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum. Example 2: Input: grid = [[1,2,3],[4,5,6]] Output: 1..
2022. 8. 17.