Skip to content

Commit fb809df

Browse files
authored
Add files via upload
1 parent a9992b1 commit fb809df

5 files changed

+64
-0
lines changed

Maximum element in dictionary.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from collections import Counter
2+
3+
dict= {'item1': 45.50, 'item2':35, 'item3': 41.30, 'item4':55, 'item5': 24}
4+
k = Counter(dict)
5+
6+
# Finding 3 highest values
7+
high = k.most_common(3)
8+
9+
print("Initial Dictionary:")
10+
print(dict, "\n")
11+
12+
13+
print("Dictionary with 3 highest values:")
14+
print("Keys: Values")
15+
16+
for i in high:
17+
print(i[0]," :",i[1]," ")

Merge two dictionary.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def merge(dict1, dict2):
2+
return(dict2.update(dict1))
3+
4+
dict1= {'R': 'Red', 'B': 'Black', 'P':'Pink'}
5+
dict2= {'G': 'Green', 'W': 'White'}
6+
7+
print(merge(dict1, dict2))
8+
print(dict2)

Most frequent element in a list.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def most_frequent(List):
2+
return max(set(List))
3+
4+
List= ['PHP','PHP','Python','PHP','Python','JS','Python','Python','PHP','Python']
5+
print(most_frequent(List))

Nested Dictionary.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def nested_dictionary(l1, l2, l3):
2+
result = [{x: {y: z}} for (x, y, z) in zip(l1, l2, l3)]
3+
return result
4+
5+
student_id = ["S001", "S002", "S003", "S004"]
6+
student_name = ["Adina Park", "Leyton Marsh", "Duncan Boyle", "Saim Richards"]
7+
student_grade = [85, 98, 89, 92]
8+
print("Original strings:")
9+
print(student_id)
10+
print(student_name)
11+
print(student_grade)
12+
print("\nNested dictionary:")
13+
ch='a'
14+
print(nested_dictionary(student_id, student_name, student_grade))

Window in another string.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import collections
2+
def min_window(str1, str2):
3+
result_char, missing_char = collections.Counter(str2), len(str2)
4+
i = p = q = 0
5+
for j, c in enumerate(str1, 1):
6+
missing_char -= result_char[c] > 0
7+
result_char[c] -= 1
8+
if not missing_char:
9+
while i < q and result_char[str1[i]] < 0:
10+
result_char[str1[i]] += 1
11+
i += 1
12+
if not q or j - i <= q - p:
13+
p, q = i, j
14+
return str1[p:q]
15+
16+
str1 = "PRWSOERIUSFK"
17+
str2 = "OSU"
18+
print("Original Strings:\n",str1,"\n",str2)
19+
print("Minimum window:")
20+
print(min_window(str1,str2))

0 commit comments

Comments
 (0)