slice32 1218. Remove First and Last Character It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters. Solution: def remove_char(s: str, limit: int = 1): return s[limit:-limit] 2022. 12. 18. 1020. Convert a string to an array Write a function to split a string and convert it into an array of words. Examples (Input ==> Output): "Robin Singh" ==> ["Robin", "Singh"] "I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"] Solution: from typing import List def string_to_array(s: str) -> List[str]: return split(s) def split(s: str, c: str = " ") -> List[str]: list, ci = [], 0 for i.. 2022. 10. 20. 1019. Is it a palindrome? Write a function that checks if a given string (case insensitive) is a palindrome. Solution: def is_palindrome(s): target = s.lower() for i in range(len(target)//2): if target[i] != target[-i-1]: return False return True def is_palindrome(s): s = s.lower() return s == s[::-1] 2022. 10. 19. 1005. Palindrome Strings Palindrome strings A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. This includes capital letters, punctuation, and word dividers. Implement a function that checks if something is a palindrome. If the input is a number, convert it to string first. Examples(Input ==> Output) "anna" ==> true "walter" ==> false 12321 ==> true 123456 =.. 2022. 10. 5. 0930. Count of positives, sum of negatives Given an array of integers. Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. 0 is neither positive nor negative. If the input is an empty array or is null, return an empty array. Example For input [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15], you should return [10, -65]. Solution: def sorted_arr(func): def w.. 2022. 9. 30. 0921. Sum without highest and lowest number Task Sum all the numbers of a given array ( cq. list ), except the highest and the lowest element ( by value, not by index! ). The highest or lowest element respectively is a single element at each edge, even if there are more than one with the same value. Mind the input validation. Example { 6, 2, 1, 8, 10 } => 16 { 1, 1, 11, 2, 3 } => 6 Input validation If an empty value ( null, None, Nothing .. 2022. 9. 21. 이전 1 2 3 4 5 6 다음