Skip to content

Commit 1f78b3e

Browse files
committed
python ex
1 parent 4a43608 commit 1f78b3e

File tree

5 files changed

+186
-0
lines changed

5 files changed

+186
-0
lines changed

stepic/.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import calendar
2+
3+
cal = calendar.month(2023, 1)
4+
5+
print(cal)
6+
7+
print(type(cal))
8+
9+
###################
10+
11+
cal = calendar.month(2023, 1, w=5, l=5)
12+
13+
print(cal)
14+
15+
#############
16+
17+
cal_mnth = calendar.prmonth(2023, 1)
18+
19+
print(cal_mnth)
20+
21+
22+
###############
23+
24+
cal_yr = calendar.calendar(2023)
25+
26+
print(cal_yr)
27+
28+
######
29+
# set num of month per column
30+
31+
cal_out = calendar.calendar(2023, c=5, m=2)
32+
33+
print(cal_out)
34+
35+
######
36+
# set first day as Saturday
37+
38+
calendar.setfirstweekday(calendar.SATURDAY)
39+
40+
print(calendar.month(2023, 1))
41+
42+
#######
43+
# change locale month representation
44+
45+
46+
# ltc_de = calendar.LocaleTextCalendar(locale='de_de')
47+
48+
# print(ltc_de.formatmonth(2019, 1))
49+
50+
# ltc_ja = calendar.LocaleTextCalendar(locale='ja_jp')
51+
52+
# print(ltc_ja.formatmonth(2019, 1))
53+
54+
55+
###################
56+
# represent calendar as HTML
57+
58+
html_cal = calendar.HTMLCalendar()
59+
60+
print(html_cal.formatmonth(2023, 1, withyear=False))
61+
# TODO showcase: save html and open it in browser
62+
print('#########################')
63+
print(html_cal.formatyear(2023, width=5))
64+
# TODO showcase: save html and open it in browser
65+
###
66+
print(html_cal.cssclasses)
67+
# Todo: add more pop names to weekdays (from songs, movies, etc)
68+
html_cal.cssclasses = ['manic_monday', 'ruby_tuesday', 'wednesday_adams', 'black_thursday', 'good_friday', 'saturday', 'sunday_bloody_sunday']
69+
70+
print(html_cal.cssclasses)
71+
72+
####
73+
74+
html_cal_day = calendar.HTMLCalendar(firstweekday=5)
75+
print(html_cal_day.formatmonth(2023, 1))
76+
# again, save html and output in browser
77+
78+
# #### change locale
79+
# lhc = calendar.LocaleHTMLCalendar(firstweekday=6, locale='ja_jp')
80+
81+
# print(lhc.formatmonth(2019, 1))
82+
83+
#### Calendars as lists
84+
import pprint
85+
pprint.pprint(calendar.monthcalendar(2023, 1))
86+
87+
##
88+
calendar.setfirstweekday(5)
89+
90+
pprint.pprint(calendar.monthcalendar(2023, 1))
91+
92+
###
93+
94+
caldr = calendar.Calendar(firstweekday=5)
95+
pprint.pprint(caldr.monthdayscalendar(2023, 1))
96+
print('##########')
97+
pprint.pprint(caldr.yeardayscalendar(2023), depth=3)
98+
print('##########')
99+
100+
pprint.pprint(caldr.yeardayscalendar(2023, width=5), depth=3)
101+
102+
103+
#### get cal as list of tuples
104+
105+
pprint.pprint(caldr.monthdays2calendar(2023, 1))
106+
107+
pprint.pprint(caldr.monthdatescalendar(2023, 1))
108+
109+
# type on the command line:
110+
# python3 -m calendar 2023 1
111+
# python3 -m calendar -h
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
4+
def main():
5+
6+
ctemps = [0, 10, 44, 100, 120]
7+
8+
temp_dict = {t: (t * 9/5) + 32 for t in ctemps if t < 100}
9+
print(temp_dict)
10+
print(temp_dict[10])
11+
12+
13+
14+
team1 = {"Adams": 14, "Pearse": 28, "Hendrics": 44, "Ericcson": 1}
15+
team2 = {"Parquette": 16, "Duvall": 67, "Lafleur": 5}
16+
17+
new_team = {k: v for team in (team1, team2) for k, v in team.items()}
18+
print(new_team)
19+
20+
21+
22+
if __name__ == "__main__":
23+
main()

stepic/python_fullstack/list_comp.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
2+
3+
4+
#### for loop #####
5+
6+
squares = []
7+
for number in numbers:
8+
squares.append(number**2)
9+
print(squares)
10+
11+
#### list comp ####
12+
13+
squares = [number**2 for number in numbers]
14+
print(squares)
15+
16+
###### list comp cond ########
17+
18+
evens = [number for number in numbers if number % 2 == 0]
19+
print('evens', evens)
20+
21+
####### list comp pairs ##############
22+
23+
numbers1 = [0, 1, 2, 3]
24+
numbers2 = [4, 5, 6, 7]
25+
26+
pairs = [(number1, number2) for number1 in numbers1 if number1 % 2 == 0 for number2 in numbers2 if number2 % 2 == 1]
27+
print(pairs)
28+
29+
###### list comp range ###########
30+
31+
lists = [[i for i in range(j)] for j in range(5)]
32+
print('lists', lists)

stepic/python_fullstack/set_comp.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
3+
4+
def main():
5+
6+
ctemps = [6, 11, 13, 16, 11, 23, 45, 33, 13, 24, 12, 17, 22]
7+
8+
far_temps1 = [(t * 9/5) + 32 for t in ctemps]
9+
far_temps2 = {(t * 9/5) + 32 for t in ctemps}
10+
11+
print(far_temps1)
12+
print(far_temps2)
13+
14+
15+
temp_str = "The quick brown fox jumped over the lazy dog"
16+
characters = {c.upper() for c in temp_str if not c.isspace() }
17+
print(characters)
18+
19+
if __name__ == "__main__":
20+
main()

0 commit comments

Comments
 (0)