diff --git a/Python/CollectionsOrderedDict.py b/Python/CollectionsOrderedDict.py new file mode 100644 index 0000000..80e56a6 --- /dev/null +++ b/Python/CollectionsOrderedDict.py @@ -0,0 +1,18 @@ +/* +Solution For: collections.OrderedDict +https://www.hackerrank.com/challenges/py-collections-ordereddict/problem +*/ +from collections import OrderedDict +n = int(input()) +ordered_dictionary = OrderedDict({}) +for i in range(n): + x = input().split(' ') + y = int(x[-1]) + x.pop() + x1 = ' '.join(x) + if x1 in ordered_dictionary: + ordered_dictionary[x1] += y + else: + ordered_dictionary[x1] = y +for i,j in ordered_dictionary.items(): + print(i,j) diff --git a/Python/DesignerDoorMat.py b/Python/DesignerDoorMat.py new file mode 100644 index 0000000..fee713f --- /dev/null +++ b/Python/DesignerDoorMat.py @@ -0,0 +1,14 @@ +/* +Solution For: Desginer Door Mat +https://www.hackerrank.com/challenges/designer-door-mat/problem +*/ + +n,m = map(int,input().split()) +#Abovepart +for i in range(1,((n-1)//2)+1): + print(((2*i-1)*".|.").center(m,'-')) +#Middlepart +print("WELCOME".center(m,'-')) +#belowpart +for i in range(((n-1)//2),0,-1): + print(((2*i-1)*".|.").center(m,'-')) diff --git a/Python/ItertoolsCombination.py b/Python/ItertoolsCombination.py new file mode 100644 index 0000000..d92e433 --- /dev/null +++ b/Python/ItertoolsCombination.py @@ -0,0 +1,12 @@ +/* +Solution for Itertools.combination() +https://www.hackerrank.com/challenges/itertools-combinations/problem + */ +from itertools import combinations +x,y = input().split() +x = list(x) +x.sort() +for i in range(1,int(y)+1): + z = list(combinations(x,i)) + for j in z: + print(''.join(j)) diff --git a/Python/SetOperations.py b/Python/SetOperations.py new file mode 100644 index 0000000..23f2e0d --- /dev/null +++ b/Python/SetOperations.py @@ -0,0 +1,22 @@ +/* +Solution For: Set .discard(), .remove() & .pop() +https://www.hackerrank.com/challenges/py-set-discard-remove-pop/problem +*/ + +n = int(input()) +s = set(map(int, input().split())) +noc = int(input()) +commands = { + "pop" : lambda a:a.pop(), + "remove" : lambda a,b:a.remove(b), + "discard" : lambda a,b : a.discard(b) +} +for i in range(noc): + z = input() + z1 = z.split() + command = z1[0] + try: + commands[command](s,int(z1[1])) + except IndexError: + commands[command](s) +print(sum(s))