Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
python codewars
#python 3.5.2 print("#" + "-" * 40 + "#") print("Count the unique duplicates") ss = None def check_dup(): if ss is None: return 0 elems = [i for i in ss.lower() if ss.count(i) != 1] count = len(list(set(elems))) return count print (">>>", check_dup()) print("\n") print("#" + "-" * 40 + "#") print("Make a program that filters a list of strings and returns a list with only your friends name in it.") print("If a name has exactly 4 letters in it, you can be sure that it has to be a friend of yours!") print("Otherwise, you can be sure he's not...") print('Ex: Input = ["Ryan", "Kieran", "Jason", "Yous"], Output = ["Ryan", "Yous"] ') print("Note: keep the original order of the names in the output") peoples = ["Ryan", "Kieran", "Jason", "Yous"] def friend(x): return list(filter(lambda y: len(y) == 4, x)) print(">>>", friend(peoples)) print("\n") print("#" + "-" * 40 + "#") print("Given a set of numbers, return the additive inverse of each.") print("Each positive becomes negatives, and the negatives become positives.") print("invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5]") print("invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5]") print("invert([]) == []") nums = [1, -2, 3, -4, 5] def invert(lst): return [-i for i in lst] print(">>>", invert(nums)) print("\n") def calc_ticket_change(): print("#" + "-" * 40 + "#") print('The new "Avengers" movie has just been released!') print("There are a lot of people at the cinema box office standing in a huge line. ") print('Each of them has a single 100, 50 or 25 dollars bill. An "Avengers" ticket costs 25 dollars.') ppls = [25, 25, 25, 25, 50, 100, 50] def tickets(people): ticket_price = 25 money_in_stash = 0 for i in people: if i == ticket_price: money_in_stash += ticket_price if i > ticket_price: if money_in_stash - i + ticket_price < 0: return "NO" else: money_in_stash -= (i - ticket_price) return "YES" print(">>>", calc_ticket_change()) print("\n") print("#" + "-" * 40 + "#") print("Given a string, you have to return a string in which each character (case-sensitive) is repeated once") def double_char(s): return "".join([i*2 for i in s]) print(double_char("alloha, World!!12")) print("#" + "-" * 40 + "#") print("Our task is to find the minimum sum which is obtained from summing each Two integers product.") print(" ### FAIL WITH THIS TASK :( SOLUTIONS IS COPYPASTED ###") def min_sum(arr): sum = 0 while len(arr) != 0: sum += min(arr)*max(arr) arr.remove(min(arr)) arr.remove(max(arr)) return sum #def min_sum(arr): # arr.sort() # left, right, res = 0, len(arr) - 1, 0 # while left < right: # res += arr[left] * arr[right] # left += 1 # right -= 1 # return res print(">>>",min_sum([2, 4, 5, 3, 7, 8, 43, 32, 12, 12, 12, 45])) #print(min_sum([2, 4, 5, 3, 7, 8]))
run
|
edit
|
history
|
help
0
regu
24jan py
for project 1
HW selectionsort using while
PySlots3
Code hello world
abc
My code 4
Add missing persons
h