ORD8 1225. Switcheroo Given a string made up of letters a, b, and/or c, switch the position of letters a and b (change a to b and vice versa). Leave any incidence of c untouched. Example: 'acb' --> 'bca' 'aabacbaa' --> 'bbabcabb' Solution: def switcheroo(s): return s.translate(str.maketrans("ab", "ba")) def switcheroo(s): return s.translate({ord('a'): 'b', ord('b'): 'a'}) 2022. 12. 25. 1214. Find the position! When provided with a letter, return its position in the alphabet. Input :: "a" Ouput :: "Position of alphabet: 1" Solution: def position(alphabet): return f"Position of alphabet: {ord(alphabet)-96}" 2022. 12. 14. 0922. Love vs friendship If a = 1, b = 2, c = 3 ... z = 26 Then l + o + v + e = 54 and f + r + i + e + n + d + s + h + i + p = 108 So friendship is twice stronger than love :-) The input will always be in lowercase and never be empty. Solution: def words_to_marks(s: str, ord_num: int = 96): return sum(ord(i)-ord_num for i in s) 2022. 9. 22. 5 without numbers !! Write a function that always returns 5 Sounds easy right? Just bear in mind that you can't use any of the following characters: 0123456789*+-/ Good luck :) Solution: def unusual_five(): return int([i for i in str(ord("A"))].pop()) Other Solution: def unusual_five(): return len("five!") def unusual_five(): return ord("") 2022. 8. 19. Printer Errors In a factory a printer prints labels for boxes. For one kind of boxes the printer has to use colors which, for the sake of simplicity, are named with letters from a to m. The colors used by the printer are recorded in a control string. For example a "good" control string would be aaabbbbhaijjjm meaning that the printer used three times color a, four times color b, one time color h then one time .. 2022. 7. 31. Highest Scoring Word Given a string of words, you need to find the highest scoring word. Each letter of a word scores points according to its position in the alphabet: a = 1, b = 2, c = 3 etc. You need to return the highest scoring word as a string. If two words score the same, return the word that appears earliest in the original string. All letters will be lowercase and all inputs will be valid. Solution: def high.. 2022. 7. 28. 이전 1 2 다음