본문 바로가기

Python345

1229. Parts of a list Write a function partlist that gives all the ways to divide a list (an array) of at least two elements into two non-empty parts. Each two non empty parts will be in a pair (or an array for languages without tuples or a structin C - C: see Examples test Cases - ) Each part will be in a string Elements of a pair must be in the same order as in the original array. Examples of returns in different l.. 2022. 12. 30.
1228. Kata Example Twist This is an easy twist to the example kata (provided by Codewars when learning how to create your own kata). Add the value "codewars" to the array websites/Websites 1,000 times. Solution: websites = ["codewars" for _ in range(1000)] websites = ["codewars"] * 1000 2022. 12. 28.
1227. CSV representation of array Create a function that returns the CSV representation of a two-dimensional numeric array. Example: input: [[ 0, 1, 2, 3, 4 ], [ 10,11,12,13,14 ], [ 20,21,22,23,24 ], [ 30,31,32,33,34 ]] output: '0,1,2,3,4\n' +'10,11,12,13,14\n' +'20,21,22,23,24\n' +'30,31,32,33,34' Array's length > 2. Solution: def to_csv_text(array): return '\n'.join(','.join(map(str, i)) for i in array) 2022. 12. 27.
1226. Alphabet war Introduction There is a war and nobody knows - the alphabet war! There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. Task Write a function that accepts fight string consists of only small letters and return who wins the fight. When the left side wins return Left side wins!, when the right side wins return Right sid.. 2022. 12. 27.
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.
1224. Regex count lowercase letters Your task is simply to count the total number of lowercase letters in a string. Examples lowercaseCount("abc"); ===> 3 lowercaseCount("abcABC123"); ===> 3 lowercaseCount("abcABC123!@€£#$%^&*()_-+=}{[]|\':;?/>. 2022. 12. 25.