Skip to content

Commit 3fdbc2a

Browse files
author
Mari Wahl
committed
cleaning up and organizing old problems (builtin)
1 parent 6afe96f commit 3fdbc2a

File tree

106 files changed

+478
-1470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+478
-1470
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,9 @@ src/
3535

3636
└── trees
3737

38-
└── searching_and_sorting
39-
40-
├── searching
38+
└── bitwise
4139

42-
├── sorting
43-
44-
└── Extra Interview Problems
40+
└── searching_and_sorting
4541

4642
└── USEFUL
4743

src/EXTRA_INTERVIEW_PROBLEMS/math_arrays_and_strings/rev_string.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/builtin_structures/dicts/OrderedDict_example.py renamed to src/USEFUL/basic_examples/example_OrderedDict.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#!/usr/bin/python3
2-
# mari von steinkirch @2013
3-
# steinkirch at gmail
1+
#!/usr/bin/env python
2+
3+
__author__ = "bt3"
44

55
from collections import OrderedDict
66

77
def OrderedDict_example():
8-
''' show some examples for OrderedDict '''
9-
''' keep the order of insertion.
8+
''' show some examples for OrderedDict '''
9+
''' keep the order of insertion.
1010
maintains a doubly linked list, so size is more than twice than normal dict'''
11-
11+
1212

1313
pairs = [('a', 1), ('b',2), ('c',3)]
14-
14+
1515
d1 = {}
1616
for key, value in pairs:
1717
if key not in d1:

src/builtin_structures/dicts/Counter_example.py renamed to src/USEFUL/basic_examples/example_counter.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
#!/usr/bin/python3
2-
# mari von steinkirch @2013
3-
# steinkirch at gmail
1+
#!/usr/bin/env python
2+
3+
__author__ = "bt3"
44

55
from collections import Counter
66

77
def Counter_example():
8-
''' show some examples for Counter '''
9-
''' it is a dictionary that maps the items to the number of occurences '''
8+
''' it is a dictionary that maps the items to the number of occurrences '''
109
seq1 = [1, 2, 3, 5, 1, 2, 5, 5, 2, 5, 1, 4]
1110
seq_counts = Counter(seq1)
1211
print(seq_counts)
13-
12+
1413
''' we can increment manually or use the update() method '''
1514
seq2 = [1, 2, 3]
1615
seq_counts.update(seq2)
1716
print(seq_counts)
18-
17+
1918
seq3 = [1, 4, 3]
2019
for key in seq3:
2120
seq_counts[key] += 1
2221
print(seq_counts)
23-
22+
2423
''' also, we can use set operations such as a-b or a+b '''
2524
seq_counts_2 = Counter(seq3)
26-
print(seq_counts_2)
27-
print(seq_counts + seq_counts_2)
25+
print(seq_counts_2)
26+
print(seq_counts + seq_counts_2)
2827
print(seq_counts - seq_counts_2)
29-
28+
3029
if __name__ == '__main__':
3130
Counter_example()
3231

src/builtin_structures/dicts/defaultdict_example.py renamed to src/USEFUL/basic_examples/example_defaultdict.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#!/usr/bin/python3
2-
# mari von steinkirch @2013
3-
# steinkirch at gmail
1+
#!/usr/bin/env python
2+
3+
__author__ = "bt3"
44

55
from collections import defaultdict
66

77
def defaultdict_example():
8-
''' show some examples for defaultdicts '''
9-
pairs = {('a', 1), ('b',2), ('c',3)}
10-
8+
''' show some examples for defaultdicts '''
9+
pairs = {('a', 1), ('b',2), ('c',3)}
10+
1111
d1 = {}
1212
for key, value in pairs:
1313
if key not in d1:

src/builtin_structures/dicts/setdeault_example.py renamed to src/USEFUL/basic_examples/example_setdefault.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/usr/bin/python3
2-
# mari von steinkirch @2013
3-
# steinkirch at gmail
1+
#!/usr/bin/env python
2+
3+
__author__ = "bt3"
44

55

66
def usual_dict(dict_data):
@@ -28,7 +28,7 @@ def test_setdef(module_name='this module'):
2828
('key2', 'value5'),)
2929
print(usual_dict(dict_data))
3030
print(setdefault_dict(dict_data))
31-
31+
3232
s = 'Tests in {name} have {con}!'
3333
print(s.format(name=module_name, con='passed'))
3434

0 commit comments

Comments
 (0)