본문 바로가기

Python345

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.
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 --.. 2023. 2. 7.
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]:.. 2023. 2. 5.
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(.. 2023. 2. 4.