List Filtering
In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out. Example filter_list([1,2,'a','b']) == [1,2] filter_list([1,'a','b',0,15]) == [1,0,15] filter_list([1,2,'aasf','1','123',123]) == [1,2,123] Solution: def filter_list(l): return [i for i in l if isinstance(i, int)]
2022. 8. 11.
Sum of a sequence
Your task is to make function, which returns the sum of a sequence of integers. The sequence is defined by 3 non-negative values: begin, end, step (inclusive). If begin value is greater than the end, function should returns 0 Examples 2,2,2 --> 2 2,6,2 --> 12 (2 + 4 + 6) 1,5,1 --> 15 (1 + 2 + 3 + 4 + 5) 1,5,3 --> 5 (1 + 4) Solotion: def sequence_sum(begin_number, end_number, step): return sum(ra..
2022. 8. 10.
Find the unique number
There is an array with some numbers. All numbers are equal except for one. Try to find it! find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2 find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55 It’s guaranteed that array contains at least 3 numbers. The tests contain some very huge arrays, so think about performance. Solution: def find_uniq(arr): n = arr[0] == arr[-1] and arr[0] or arr[1] return [i for i in arr if n != i..
2022. 8. 8.