From bd4855f1b9b3f45ecdcad43991eaa522667a78dd Mon Sep 17 00:00:00 2001 From: EGORDYU Date: Wed, 17 May 2023 10:00:18 -0600 Subject: [PATCH] deliverable --- problems.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 problems.py diff --git a/problems.py b/problems.py new file mode 100644 index 0000000..b84e590 --- /dev/null +++ b/problems.py @@ -0,0 +1,61 @@ +vec = [[1,2,3], [4,5,6], [7,8,9]] +def flatten (list): + flattened = [] + for arr in list: + for item in arr: + flattened.append(item) + return flattened + +print(flatten(vec)) + + +def palindrome(word): + reversed_word = word[::-1] + return word == reversed_word + +print(palindrome('abba')) # Output: True +print(palindrome('hello')) # Output: False + + + +def most_used(word): + most_common_char = max(word, key=word.count) + return most_common_char + +print(most_used('hello')) # Output: 'l' + + + + +def array_split(arr, split): + chunks = [] + while len(arr) > 0: + chunks.append(arr[:split]) + arr = arr[split:] + return chunks + + +print(array_split([1, 2, 3, 4], 2)) # Output: [[ 1, 2], [3, 4]] +print(array_split([1, 2, 3, 4, 5], 2)) # Output: [[ 1, 2], [3, 4], [5]] +print(array_split([1, 2, 3, 4, 5, 6, 7, 8], 3)) # Output: [[ 1, 2, 3], [4, 5, 6], [7, 8]] +print(array_split([1, 2, 3, 4, 5], 4)) # Output: [[ 1, 2, 3, 4], [5]] +print(array_split([1, 2, 3, 4, 5], 10)) # Output: [[ 1, 2, 3, 4, 5]] + + + + + + + + +import random + +def random_array(arr): + random.shuffle(arr) + return(arr) + + +my_arr = ['banana','orange','ketchup','lettuce'] +print(random_array(my_arr)) + +