Skip to content

Commit 567a892

Browse files
committed
calendar script added
1 parent 6de9489 commit 567a892

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

calender_print.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'''Python Quick Codes: Generate the calender of any year.
2+
Using Python in-built module Calendar
3+
'''
4+
5+
import calendar
6+
7+
# Get the year from user
8+
year = int(input("Enter year: "))
9+
10+
# Set first week day of the calender as Monday
11+
calendar.setfirstweekday(calendar.MONDAY)
12+
13+
# Print the calender. m = months in a row.
14+
print(calendar.calendar(year, m=4))

collection_mod.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'''Python Quick Codes: Find the character with the maximum count in a sentence.
2+
'''
3+
4+
import collections
5+
6+
sentence = "A quick yellow fox ran together a very large Python"
7+
8+
# Print a dictionary {letter: number of occurrences} including blank space.
9+
print(collections.Counter(sentence))
10+
11+
# Print a list of five most common (letter, count) including blank space.
12+
print(collections.Counter(sentence).most_common(5))

count_in_python.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 'Find' is a method of strings. It returns the
2+
# the lowest index of the string where the substring is found
3+
an_str = "hello world"
4+
print(an_str.find("e"))
5+
print(an_str.find("or"))
6+
7+
# Count is a method on str, list, tuple to count the number of
8+
# occurrences of an element.
9+
a_list = [1, 2, 3, 4, 2, 4, 2]
10+
another_list = ['b', 'h', 'l', 'h']
11+
12+
print(a_list.count(2))
13+
print(another_list.count('h'))
14+
15+
an_str = "hello world"
16+
print(an_str.count("o"))
17+
18+
print(dir(tuple))
19+
print(dir(set))

count_odd.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'''🚀 Python Quick Codes: Count total odd numbers in a list.'''
2+
3+
numbers = [3, 2, 5, 4, 6, 8, 9, 5, 6, 7, 8, 5]
4+
5+
# 📋 Method-1: Using List comprehension
6+
odd_nums = [num for num in numbers if num % 2 != 0]
7+
print(f"Odd numbers: {odd_nums}")
8+
print(f"Total odds: {len(odd_nums)}")
9+
10+
# 📋 Method-2: Using normal for loop
11+
odd_count = 0
12+
for num in numbers:
13+
if num % 2 != 0:
14+
odd_count += 1
15+
print(f"Total odds: {odd_count}")
16+
17+
# 📋 Method-3: Using Lambda Expression
18+
odd_count = len(list(filter(lambda x: x % 2 != 0, numbers)))
19+
print(f"Total odds: {odd_count}")
20+
21+
# 👩‍💻 See you soon, Till then Keep Improving!!!🎯

0 commit comments

Comments
 (0)