Skip to content

Commit de6a577

Browse files
authored
Merge pull request #52 from HighnessAtharva/master
Ported from Python2 to Python3 + several fixes
2 parents 18467c8 + bdf89e4 commit de6a577

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+244
-192
lines changed

BasicDataTypes/Lists.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
Problem : https://www.hackerrank.com/challenges/python-lists/problem
99
"""
1010

11+
1112
if __name__ == "__main__":
1213
N = int(input())
1314
ar = []
14-
for i in range(N):
15+
for _ in range(N):
1516
command_args = input().strip().split(" ")
1617
cmd = command_args[0]
1718
if cmd == "print":

BuiltIns/AnyorAll.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
Updated : 29 August 2022
99
Problem : https://www.hackerrank.com/challenges/any-or-all/problem
1010
"""
11+
1112
n = input()
1213
ar = input().split()
13-
print(all([int(i) > 0 for i in ar]) and any([i == i[::-1] for i in ar]))
14+
print(all(int(i) > 0 for i in ar) and any(i == i[::-1] for i in ar))
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
'''
1+
"""
22
Title : Standardize Mobile Number Using Decorators
33
Subdomain : Closures and Decorators
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/standardize-mobile-number-using-decorators/problem
8-
'''
8+
"""
9+
10+
911
# Enter your code here. Read input from STDIN. Print output to STDOUT
10-
n=int(raw_input())
11-
ar=[]
12-
for i in range(0,n):
13-
tmp_str=raw_input()
14-
tmp_str=tmp_str[len(tmp_str)-10:]
12+
n = int(input())
13+
ar = []
14+
for _ in range(n):
15+
tmp_str = input()
16+
tmp_str = tmp_str[len(tmp_str) - 10 :]
1517
ar.append(tmp_str)
16-
18+
1719
ar.sort()
18-
for i in range(0,len(ar)):
19-
print "+91 "+ar[i][:5]+" "+ar[i][5:]
20+
for item in ar:
21+
print(f"+91 {item[:5]} {item[5:]}")

Collections/CollectionsOrderedDict.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
Domain : Python
55
Author : Ahmedur Rahman Shovon
66
Created : 15 July 2016
7+
Updated : 08 February 2023
78
Problem : https://www.hackerrank.com/challenges/py-collections-ordereddict/problem
89
"""
10+
911
import collections
1012
import re
1113

1214
n = int(input())
1315
item_od = collections.OrderedDict()
14-
for i in range(n):
16+
for _ in range(n):
1517
record_list = re.split(r"(\d+)$", input().strip())
1618
item_name = record_list[0]
1719
item_price = int(record_list[1])
1820
if item_name not in item_od:
1921
item_od[item_name] = item_price
2022
else:
2123
item_od[item_name] = item_od[item_name] + item_price
22-
2324
for i in item_od:
24-
print(i + str(item_od[i]))
25+
print(f"{i}{item_od[i]}")

Collections/Collectionsdeque.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/py-collections-deque/problem
88
"""
9+
910
import collections
1011

1112
n = int(input())
1213
d = collections.deque()
13-
for i in range(n):
14+
for _ in range(n):
1415
cmd = list(input().strip().split())
1516
opt = cmd[0]
16-
if opt == "pop":
17-
d.pop()
18-
elif opt == "popleft":
19-
d.popleft()
20-
elif opt == "append":
17+
if opt == "append":
2118
d.append(int(cmd[1]))
2219
elif opt == "appendleft":
2320
d.appendleft(int(cmd[1]))
21+
elif opt == "pop":
22+
d.pop()
23+
elif opt == "popleft":
24+
d.popleft()
2425
for i in d:
2526
print(i, end=" ")

Collections/Collectionsnamedtuple.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/py-collections-namedtuple/problem
88
"""
9+
910
n = int(input())
1011
col_list = list(input().split())
1112
marks_col = col_list.index("MARKS")
1213
marks_list = []
13-
for i in range(n):
14+
for _ in range(n):
1415
info_list = list(input().split())
1516
marks_list.append(float(info_list[marks_col]))
1617
print(sum(marks_list) / n)

Collections/DefaultDictTutorial.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/defaultdict-tutorial/problem
88
"""
9+
910
from collections import defaultdict
1011

1112
d = defaultdict(list)
1213
n, m = map(int, input().split())
1314
for i in range(n):
1415
w = input()
1516
d[w].append(str(i + 1))
16-
for j in range(m):
17+
for _ in range(m):
1718
w = input()
1819
print(" ".join(d[w]) or -1)

Collections/MostCommon.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/most-commons/problem
88
"""
9+
910
import collections
1011

1112
s = sorted(input().strip())
@@ -18,5 +19,5 @@
1819
s_counter[i],s_counter[j] = s_counter[j],s_counter[i]
1920
"""
2021
s_counter = sorted(s_counter, key=lambda x: (x[1] * -1, x[0]))
21-
for i in range(0, 3):
22+
for i in range(3):
2223
print(s_counter[i][0], s_counter[i][1])

Collections/PilingUp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/piling-up/problem
88
"""
9+
910
from collections import deque
1011

1112
cas = int(input())
12-
for t in range(cas):
13+
for _ in range(cas):
1314
n = int(input())
1415
dq = deque(map(int, input().split()))
1516
possible = True

Collections/collectionsCounter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
Created : 15 July 2016
77
Problem : https://www.hackerrank.com/challenges/collections-counter/problem
88
"""
9+
910
x = int(input())
1011
shoe_size = list(map(int, input().split()))
1112
n = int(input())
1213
sell = 0
13-
for i in range(n):
14+
for _ in range(n):
1415
s, p = map(int, input().split())
1516
if s in shoe_size:
1617
sell = sell + p

0 commit comments

Comments
 (0)