This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def basic_op(operator, value1, value2): | |
| """ Your task is to create a function that does four basic mathematical operations. | |
| The function should take three arguments - operation(string/char), value1(number), value2(number). | |
| The function should return result of numbers after applying the chosen operation.""" | |
| return eval("{}{}{}".format(value1, operator, value2)) | |
| basic_op('+', 2, 3) # 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import difflib | |
| from difflib import Differ | |
| string1 = 'gvgbf' | |
| string2 = 'gvgbf' | |
| def difference(first_string, second_string): | |
| """This function compares two strings between each other and returns an answer whether there are some differences | |
| or not""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def create_phone_number(n): | |
| """Write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those | |
| numbers in the form of a phone number. """ | |
| phone_numbers = ''.join(map(str, n)) | |
| return f'({phone_numbers[0:3]}) {phone_numbers[3:6]}-{phone_numbers[6:10]}' | |
| print(create_phone_number([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])) # (123) 456-7890 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import Counter | |
| def delete_nth(order, max_e): | |
| """Given a list lst and a number N, create a new list that contains each number of lst at most N times without | |
| reordering. For example if N = 2, and the input is [1,2,3,1,2,1,2,3], you take [1,2,3,1,2], drop the next [1, | |
| 2] since this would lead to 1 and 2 being in the result 3 times, and then take 3, which leads to [1,2,3,1,2,3]. """ | |
| numbers = [] | |
| c = Counter() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def square_digits(num): | |
| """Welcome. In this kata, you are asked to square every digit of a number.""" | |
| new_numbers = [] | |
| for digit in str(num): # Iterating through the given string in num | |
| digit = int(digit) # Converting strings into ints | |
| new_numbers.append(digit * digit) # Adding calculated numbers into a new list | |
| str_numbers = ''.join(map(str, new_numbers)) # Creating a string, made of new list | |
| return int(str_numbers) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def to_jaden_case(string): | |
| """Your task is to convert strings to how they would be written by Jaden Smith. The strings are actual quotes | |
| from Jaden Smith, but they are not capitalized in the same way he originally typed them. """ | |
| capitalizing = [word.capitalize() for word in string.split()] | |
| string = ' '.join(capitalizing) | |
| return string | |
| quote = "How can mirrors be real if our eyes aren't real" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def likes(names): | |
| """Implement a function likes :: [String] -> String, which must take in input array, containing the names of | |
| people who like an item. """ | |
| if len(names) == 0: | |
| return 'no one likes this' | |
| elif len(names) == 1: | |
| return f'{names[0]} likes this' | |
| elif len(names) == 2: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def number(bus_stops): | |
| """Your task is to return number of people who are still in the bus after the last bus station (after the last | |
| array). Even though it is the last bus stop, the bus is not empty and some people are still in the bus, | |
| and they are probably sleeping there :D """ | |
| bus_stops = dict(bus_stops) | |
| inside_the_bus, outside_the_bus = [inside for inside in bus_stops.keys()], \ | |
| [outside for outside in bus_stops.values()] | |
| total = sum(inside_the_bus) - sum(outside_the_bus) | |
| return total |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def remove_smallest(numbers): | |
| """Given an array of integers, remove the smallest value. Do not mutate the original array/list. If there are | |
| multiple elements with the same value, remove the one with a lower index. If you get an empty array/list, | |
| return an empty array/list. | |
| Don't change the order of the elements that are left.""" | |
| n_copy = numbers.copy() # Creating a copy of input string, to avoid mutation in the original one | |
| try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def race(v1, v2, g): | |
| """Two tortoises named A and B must run a race. A starts with an average speed of 720 feet per hour. Young B | |
| knows she runs faster than A, and furthermore has not finished her cabbage. | |
| When she starts, at last, she can see that A has a 70 feet lead but B's speed is 850 feet per hour. How long will it | |
| take B to catch A? | |
| More info: https://bit.ly/2zobER9""" | |
| if v1 > v2: |