나는 이렇게 학습한다/Algorithm & SQL405 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)) 2023. 2. 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]: .. 2023. 2. 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.. 2023. 2. 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.. 2023. 2. 9. 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.. 2023. 2. 9. 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 2023. 2. 8. 이전 1 2 3 4 ··· 68 다음