Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f81d850

Browse files
wrote 2 more codes
1 parent a210807 commit f81d850

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

‎Day 5/2nd-most-frequent-char.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# s = input("Enter a string: ")
2+
s = 'aabababacccccc'
3+
4+
# 1: WRITING ALL THE CODE
5+
freq = dict()
6+
7+
for c in s:
8+
if c in freq:
9+
freq[c] += 1
10+
else:
11+
freq[c] = 1
12+
13+
# freq[c] = freq.get(c, 0) + 1
14+
print(freq)
15+
16+
17+
# 2: WRITING A BIT LESS CODE
18+
freq = dict()
19+
chars = set(s)
20+
for c in chars:
21+
freq[c] = s.count(c)
22+
print(freq)
23+
24+
25+
# 3: WRITING EVEN LESS CODE
26+
freq = {c:s.count(c) for c in set(s)}
27+
print(freq)
28+
29+
30+
# 4: USING INBUILT SHIT XD
31+
from collections import Counter
32+
33+
freq = Counter(s)
34+
print(freq)
35+
36+
max1, max2 = s[0], s[0]
37+
for c in freq:
38+
if freq[c] > freq[max1]:
39+
max2 = max1
40+
max1 = c
41+
elif freq[c] > freq[max2] and freq[max1] != freq[max2]:
42+
max2 = c
43+
44+
print(max2)
45+
46+
47+
items = list(freq.items())
48+
print(items)
49+
50+
items.sort(key=lambda t: t[1], reverse=True)
51+
print(items)

‎Day 5/sum-of-numbers-k.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
a = list(map(int, input('Enter an array of numbers: ').split()))
2+
k = int(input('Enter the value of K: '))
3+
4+
values = set(a)
5+
6+
for i in a:
7+
if i not in values:
8+
continue
9+
if k-i in values:
10+
print(i, k-i)
11+
values.remove(k-i)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /