Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions AnyorAll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

n = input()
ar = input().split()
print(all([int(i)>0 for i in ar]) and any([i==i[::-1] for i in ar]))
14 changes: 14 additions & 0 deletions AthleteSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


if __name__ == '__main__':
n, m = map(int, input().split())

arr = []

for _ in range(n):
arr.append(list(map(int, input().rstrip().split())))

k = int(input())

for i in sorted(arr, key= lambda x: x[k]):
print(*i)
13 changes: 13 additions & 0 deletions CompresstheString.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import itertools
s = input().strip()
s_unique_element = list(set(s))
group = []
key = []
for k,g in itertools.groupby(s):
group.append(list(g))
key.append(k)
for i in range(len(group)):
group_length = len(group[i])
k = int(key[i])
print(tuple((group_length,k)),end=' ')
10 changes: 10 additions & 0 deletions Findingthepercentage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if __name__ == '__main__':
n = int(input())
student_marks = {}
for _ in range(n):
name, *line = input().split()
scores = list(map(float, line))
student_marks[name] = scores
query_name = input()
res = sum(student_marks[query_name]) / len(student_marks[name])
print("{:.2f}".format(res))
5 changes: 5 additions & 0 deletions FindtheSecondLargestNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

if __name__ == '__main__':
n = int(input())
arr = map(int, input().split())
print(sorted(set(arr), reverse=True)[1])
5 changes: 5 additions & 0 deletions Input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

if __name__ == "__main__":
x, k = map(int, input().strip().split())
equation = input().strip()
print(eval(equation) == k)
8 changes: 8 additions & 0 deletions IterablesandIterators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from itertools import combinations
n = int(input())
ar = input().split()
k = int(input())
comb_list = list(combinations(ar,k))
a_list = [e for e in comb_list if 'a' in e]
print(len(a_list) / len(comb_list))
9 changes: 9 additions & 0 deletions ListComprehensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

if __name__ == '__main__':
x = int(input())
y = int(input())
z = int(input())
n = int(input())
ar = [[i, j, k] for i in range(x + 1) for j in range(y + 1) for k in
range(z + 1) if i + j + k != n]
print(ar)
33 changes: 33 additions & 0 deletions Lists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


if __name__ == '__main__':
N = int(input())
ar = []
for i in range(0, N):
tmp_str = input()
tmp_str_ar = tmp_str.strip().split(" ")
cmd = tmp_str_ar[0]
if cmd == "print":
print(ar)
elif cmd == "sort":
ar.sort()
elif cmd == "reverse":
ar.reverse()
elif cmd == "pop":
ar.pop()
elif cmd == "count":
val = int(tmp_str_ar[1])
ar.count(val)
elif cmd == "index":
val = int(tmp_str_ar[1])
ar.index(val)
elif cmd == "remove":
val = int(tmp_str_ar[1])
ar.remove(val)
elif cmd == "append":
val = int(tmp_str_ar[1])
ar.append(val)
elif cmd == "insert":
pos = int(tmp_str_ar[1])
val = int(tmp_str_ar[2])
ar.insert(pos, val)
15 changes: 15 additions & 0 deletions MaximizeIt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

import itertools

k, m = map(int,input().split())

main_ar = []
for i in range(k):
ar = list(map(int,input().split()))
main_ar.append(ar[1:])

all_combination = itertools.product(*main_ar)
result = 0
for single_combination in all_combination:
result = max(sum([x*x for x in single_combination])%m,result)
print(result)
14 changes: 14 additions & 0 deletions NestedLists.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

if __name__ == '__main__':
students = []
scores = []
for _ in range(int(input())):
name = input()
score = float(input())
student = [name, score]
students.append(student)
scores.append(score)
second_min_score = sorted(set(scores))[1]
student_names = sorted(
[student[0] for student in students if student[1] == second_min_score])
print("\n".join(student_names))
2 changes: 2 additions & 0 deletions PythonEvaluation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

eval(input())
6 changes: 6 additions & 0 deletions Tuples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

if __name__ == '__main__':
n = int(input())
integer_list = map(int, input().split())
t = tuple(integer_list)
print(hash(t))
8 changes: 8 additions & 0 deletions Zipped.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


N, X = map(int, input().split())
scores = []
for _ in range(X):
scores.append(list(map(float, input().split())))
for i in zip(*scores):
print(sum(i)/len(i))
4 changes: 4 additions & 0 deletions ginortS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


s = input()
print(''.join(sorted(s, key=lambda x: (x.isdigit() and int(x)%2==0, x.isdigit(), x.isupper(), x.islower(), x))))
8 changes: 8 additions & 0 deletions itertoolscombinations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from itertools import *
s,n = input().split()
n = int(n) + 1
s = sorted(s)
for i in range(1,n):
for j in combinations(s,i):
print(''.join(j))
7 changes: 7 additions & 0 deletions itertoolscombinations_with_replacement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

from itertools import *
s,n = input().split()
n = int(n)
s = sorted(s)
for j in combinations_with_replacement(s,n):
print(''.join(j))
6 changes: 6 additions & 0 deletions itertoolspermutations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import itertools
s,n = list(map(str,input().split(' ')))
s = sorted(s)
for p in list(itertools.permutations(s,int(n))):
print(''.join(p))
7 changes: 7 additions & 0 deletions itertoolsproduct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

import itertools
ar1 = list(map(int,input().split()))
ar2 = list(map(int,input().split()))
cross = list(itertools.product(ar1,ar2))
for i in cross:
print(i,end=' ')