Skip to content

Commit f04d00b

Browse files
Aseem JainAseem Jain
Aseem Jain
authored and
Aseem Jain
committed
logging
1 parent c15eb47 commit f04d00b

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

Diff for: REFERENCE_SHEET.py

+21-4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@
8080

8181
print(a)
8282

83+
#####################################
84+
# convert num to char and char to number
85+
ord('a')
86+
# >>> 97
87+
chr(97)
88+
# >>> 'a'
89+
chr(ord('a') + 3)
90+
# >>> 'd'
91+
8392
#####################################
8493
# check if char or string contains special chars, is numeric, is a negative number or alphabetic
8594

@@ -505,12 +514,20 @@ def sub_this(x: int, obj:Custom) -> str:
505514
s_k_t = sorted(m.items(),key=lambda i:i[0])
506515
s_v_t = sorted(m.items(),key=lambda i:i[1])
507516

508-
# converted sorted tuple into new map sorted by
517+
# converted tuple into map by
509518
s_k_m = {}
510-
for k,v in s_k_t: s_k_m[k]=v
519+
for k,v in s_k_t:
520+
s_k_m[k]=v
521+
522+
##### Deep clone a map by using dictionary compehension
523+
524+
# manual copy at first level
525+
deep_copied_map = { k:v.copy() for k,v in map.items() }
526+
527+
# in build method
528+
import copy
529+
deep_copied_map = copy.deepcopy(s_k_m)
511530

512-
s_v_m = {}
513-
for k,v in s_v_t: s_v_m[k]=v
514531

515532

516533
#####################################

Diff for: algorithm_and_datastructure/cache/cache_implementation.py renamed to algorithm_and_datastructure/cache/simple_cache.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,26 @@
1515
1616
"""
1717

18+
data = [ chr(ord("a")+x) for x in range(10)]
1819

19-
def sol(n):
20-
return n * 2
20+
cache = { }
21+
22+
def load_cache(x):
23+
cache[x] = [1]
24+
25+
def get_data(x):
26+
if cache.get(x):
27+
return "hit"
28+
load_cache(x)
29+
return "miss"
2130

2231

2332
test_data = [
24-
(2, 4),
25-
(4, 8),
33+
("a", "miss"),
34+
("a", "hit"),
35+
("b", "miss"),
2636
]
2737

2838
for given, expected in test_data:
29-
assert expected == sol(given)
39+
assert expected == get_data(given)
3040
print(f"Test passed for: given {given} and expected = {expected}")

Diff for: concepts/logging/simple_log.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""
2+
@Author: Aseem Jain
3+
@Linkedin: https://www.linkedin.com/in/premaseem/
4+
@Github: https://github.com/premaseem/pythonLab/tree/master/challenge
5+
6+
"""
7+
import logging
8+
LOG_FORMAT = "%(levelname)s %(asctime)s "
9+
logging.basicConfig(filename="splunk.log", format = LOG_FORMAT, level=logging.DEBUG, filemode="w")
10+
logger = logging.getLogger()
11+
logger.debug("This is broken now")
12+

Diff for: images/file_modes.png

56.5 KB
Loading

0 commit comments

Comments
 (0)