0212. Reversed sequence Build a function that returns an array of integers from n to 1 where n>0. Example : n=5 --> [5,4,3,2,1] Solution: reverse_seq = lambda n: sorted(range(1, n+1), reverse=True) def reverseseq(n): return list(range(n, 0, -1)) 나는 이렇게 학습한다/Algorithm & SQL 2023.02.13
0211. Remove duplicates from list Define a function that removes duplicates from an array of numbers and returns it as a result. The order of the sequence has to stay the same. Solution: def distinct(seq: list[int]) -> list[int]: result = [] for i in seq: if i not in result: result.append(i) return result def distinct(seq: list[int]) -> list[int]: return sorted(set(seq), key=seq.index) def distinct(seq: list[int]) -> list[int]: .. 나는 이렇게 학습한다/Algorithm & SQL 2023.02.12
0210. Is it a number? Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not. Valid examples, should return true: isDigit("3") isDigit(" 3 ") isDigit("-3.23") should return false: isDigit("3-4") isDigit(" 3 5") isDigit("3 5") isDigit("zero") Solution: def isDigit(string: str) -> bool: return string.strip().lstrip("-").replace(".", "").isd.. 나는 이렇게 학습한다/Algorithm & SQL 2023.02.10
0209. Sort the Gift Code Happy Holidays fellow Code Warriors! Santa's senior gift organizer Elf developed a way to represent up to 26 gifts by assigning a unique alphabetical character to each gift. After each gift was assigned a character, the gift organizer Elf then joined the characters to form the gift ordering code. Santa asked his organizer to order the characters in alphabetical order, but the Elf fell asleep fro.. 나는 이렇게 학습한다/Algorithm & SQL 2023.02.09
0209. Sort Out The Men From Boys Scenario Now that the competition gets tough it will Sort out the men from the boys . Men are the Even numbers and Boys are the odd!alt!alt Task Given an array/list [] of n integers , Separate The even numbers from the odds , or Separate the men from the boys!alt!alt Notes Return an array/list where Even numbers come first then odds Since , Men are stronger than Boys , Then Even numbers in ascen.. 나는 이렇게 학습한다/Algorithm & SQL 2023.02.09
0207. Divide and Conquer Given a mixed array of number and string representations of integers, add up the non-string integers and subtract this from the total of the string integers. Return as a number. Solution: def div_con(arr): x = sum(i for i in arr if isinstance(i, int)) y = sum(int(i) for i in arr if isinstance(i, str)) return x - y 나는 이렇게 학습한다/Algorithm & SQL 2023.02.08
0206. Find the nth Digit of a Number Complete the function that takes two numbers as input, num and nth and return the nth digit of num (counting from right to left). Note If num is negative, ignore its sign and treat it as a positive value If nth is not positive, return -1 Keep in mind that 42 = 00042. This means that findDigit(42, 5) would return 0 Examples(num, nth --> output) 5673, 4 --> 5 129, 2 --> 2 -2825, 3 --> 8 -456, 4 --.. 나는 이렇게 학습한다/Algorithm & SQL 2023.02.07
0205. pick a set of first elements Write a function to get the first element(s) of a sequence. Passing a parameter n (default=1) will return the first n element(s) of the sequence. If n == 0 return an empty sequence [] Examples arr = ['a', 'b', 'c', 'd', 'e'] first(arr) # --> ['a'] first(arr, 2) # --> ['a', 'b'] first(arr, 3) # --> ['a', 'b', 'c'] first(arr, 0) # --> [] Solution: def first(seq: list[str], n:int = 1) -> list[str]:.. 나는 이렇게 학습한다/Algorithm & SQL 2023.02.05
0204. Filter the number Filter the number Oh, no! The number has been mixed up with the text. Your goal is to retrieve the number from the text, can you return the number back to its original state? Task Your task is to return a number from a string. Details You will be given a string of numbers and letters mixed up, you have to return all the numbers in that string in the order they occur. Solution: def filter_string(.. 나는 이렇게 학습한다/Algorithm & SQL 2023.02.04
0203. Parse float Write function parse_float which takes a string/list and returns a number or 'none' if conversion is not possible. Solution: def parse_float(string: str) -> float | None: try: return float(string) except (ValueError, TypeError): return None 나는 이렇게 학습한다/Algorithm & SQL 2023.02.03