본문 바로가기

Python25

[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.
[LeetCode] 91. Decode Ways A message containing letters from A-Z can be encoded into numbers using the following mapping: 'A' -> "1" 'B' -> "2" ... 'Z' -> "26" To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into: "AAJF" with the grouping (1 1 10 6) "KJF" with the grouping (11 .. 2022. 12. 8.
[LeetCode] 88. Merge Sorted Array You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order. The final sorted array should not be returned by the function, but instead be stored inside the array nums1. To accommodate this, nums1 has a lengt.. 2022. 11. 15.
[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] 70. Climbing Stairs You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Example 1: Input: n = 2 Output: 2 Explanation: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps Example 2: Input: n = 3 Output: 3 Explanation: There are three ways to climb to the top. 1. 1 step + 1 step + 1 step 2... 2022. 8. 19.
[LeetCode] 69. Sqrt(x) Given a non-negative integer x, compute and return the square root of x. Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned. Note: You are not allowed to use any built-in exponent function or operator, such as pow(x, 0.5) or x ** 0.5. Example 1: Input: x = 4 Output: 2 Example 2: Input: x = 8 Output: 2 Explanation: The square.. 2022. 8. 19.
[LeetCode] 66. Plus One You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. Increment the large integer by one and return the resulting array of digits. Example 1: Input: digits = [1,2,3] Output: [1,2,4] Expl.. 2022. 8. 19.
[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.
반응형