본문 바로가기

Python345

0121. esreveR Write a function reverse which reverses a list (or in clojure's case, any list-like data structure) (the dedicated builtin(s) functionalities are deactivated) Solution: def reverse(lst): result = list() for _ in range(len(lst)): result.append(lst.pop()) return result 2023. 1. 21.
0120. Alphabet symmetry Consider the word "abode". We can see that the letter a is in position 1 and b is in position 2. In the alphabet, a and b are also in positions 1 and 2. Notice also that d and e in abode occupy the positions they would occupy in the alphabet, which are positions 4 and 5. Given an array of words, return an array of the number of letters that occupy their positions in the alphabet for each word. F.. 2023. 1. 21.
0119. Thinkful - Number Drills: Blue and red marbles You and a friend have decided to play a game to drill your statistical intuitions. The game works like this: You have a bunch of red and blue marbles. To start the game you grab a handful of marbles of each color and put them into the bag, keeping track of how many of each color go in. You take turns reaching into the bag, guessing a color, and then pulling one marble out. You get a point if you.. 2023. 1. 19.
0118. Ordered Count of Characters Count the number of occurrences of each character and return it as a (list of tuples) in order of appearance. For empty output return (an empty list). Consult the solution set-up for the exact data structure implementation depending on your language. Example: ordered_count("abracadabra") == [('a', 5), ('b', 2), ('r', 2), ('c', 1), ('d', 1)] Solution: def ordered_count(inp): from collections impo.. 2023. 1. 18.
0117. get character from ASCII Value Write a function get_char() / getChar() which takes a number and returns the corresponding ASCII char for that value. Example: get_char(65) should return: 'A' Solution: get_char = lambda x: chr(x) 2023. 1. 18.
0116. OOP: Object Oriented Piracy Ahoy matey! You are a leader of a small pirate crew. And you have a plan. With the help of OOP you wish to make a pretty efficient system to identify ships with heavy booty on board! Unfortunately for you, people weigh a lot these days, so how do you know if a ship is full of gold and not people? You begin with writing a generic Ship class / struct: class Ship: def __init__(self, draft, crew): s.. 2023. 1. 16.