Skip to content

Commit 93ce4c9

Browse files
authored
Merge branch 'master' into jayascript-patch-1
2 parents b1ee398 + 4bff241 commit 93ce4c9

Some content is hidden

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

54 files changed

+297929
-12
lines changed

binary-search/README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1-
# How to Do a Binary Search in Python?
1+
# How to Do a Binary Search in Python
22

3-
Code snippets supplementing the [How to Do a Binary Search in Python?](https://realpython.com/binary-search-python/) article on [Real Python](https://realpython.com/).
3+
Code snippets supplementing the [How to Do a Binary Search in Python](https://realpython.com/binary-search-python/) article.
4+
5+
## Usage
6+
7+
### Download Sample Dataset
8+
9+
To download a sample dataset for benchmarking, run the following script:
10+
11+
```shell
12+
$ python download_imdb.py
13+
Fetching data from IMDb...
14+
Created "names.txt" and "sorted_names.txt"
15+
```
16+
17+
### Benchmark
18+
19+
**Note:** The hash-based search algorithm requires a separate data structure, so it's not included here. Feel free to treat it as an exercise.
20+
21+
Find the index of Arnold Schwarzenegger in unsorted names using random search:
22+
23+
```shell
24+
$ python benchmark.py -a random -f names.txt 'Arnold Schwarzenegger'
25+
Loading names...ok
26+
[1/10] Found at index=215 (21.68 s)
27+
[2/10] Found at index=215 (148.10 ms)
28+
[3/10] Found at index=215 (63.49 s)
29+
[4/10] Found at index=215 (15.93 s)
30+
[5/10] Found at index=215 (23.38 s)
31+
[6/10] Found at index=215 (60.98 s)
32+
[7/10] Found at index=215 (10.14 s)
33+
[8/10] Found at index=215 (15.81 s)
34+
[9/10] Found at index=215 (5.10 s)
35+
[10/10] Found at index=215 (13.36 s)
36+
best=148.10 ms, worst=63.49 s, avg=23.00 s, median=15.87 s
37+
```
38+
39+
Find the index of Arnold Schwarzenegger in unsorted names using linear search:
40+
41+
```shell
42+
$ python benchmark.py -a linear -f names.txt 'Arnold Schwarzenegger'
43+
Loading names...ok
44+
[1/10] Found at index=215 (30.95 µs)
45+
[2/10] Found at index=215 (26.86 µs)
46+
[3/10] Found at index=215 (26.26 µs)
47+
[4/10] Found at index=215 (26.55 µs)
48+
[5/10] Found at index=215 (26.24 µs)
49+
[6/10] Found at index=215 (25.88 µs)
50+
[7/10] Found at index=215 (25.77 µs)
51+
[8/10] Found at index=215 (25.89 µs)
52+
[9/10] Found at index=215 (25.91 µs)
53+
[10/10] Found at index=215 (25.99 µs)
54+
best=25.77 µs, worst=30.95 µs, avg=26.63 µs, median=26.11 µs
55+
```
56+
57+
Find the index of Arnold Schwarzenegger in *sorted* names using binary search:
58+
59+
```shell
60+
$ python benchmark.py -a binary -f sorted_names.txt 'Arnold Schwarzenegger'
61+
Loading names...ok
62+
[1/10] Found at index=782431 (18.82 µs)
63+
[2/10] Found at index=782431 (9.19 µs)
64+
[3/10] Found at index=782431 (11.08 µs)
65+
[4/10] Found at index=782431 (9.70 µs)
66+
[5/10] Found at index=782431 (10.14 µs)
67+
[6/10] Found at index=782431 (9.35 µs)
68+
[7/10] Found at index=782431 (9.42 µs)
69+
[8/10] Found at index=782431 (8.79 µs)
70+
[9/10] Found at index=782431 (8.66 µs)
71+
[10/10] Found at index=782431 (8.79 µs)
72+
best=8.66 µs, worst=18.82 µs, avg=10.39 µs, median=9.38 µs
73+
```

flask-connexion-rest-part-2/version_1/people.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def read_all():
2020

2121
# Serialize the data for the response
2222
person_schema = PersonSchema(many=True)
23-
data = person_schema.dump(people).data
23+
data = person_schema.dump(people)
2424
return data
2525

2626

@@ -40,7 +40,7 @@ def read_one(person_id):
4040

4141
# Serialize the data for the response
4242
person_schema = PersonSchema()
43-
data = person_schema.dump(person).data
43+
data = person_schema.dump(person)
4444
return data
4545

4646
# Otherwise, nope, didn't find that person
@@ -73,14 +73,14 @@ def create(person):
7373

7474
# Create a person instance using the schema and the passed in person
7575
schema = PersonSchema()
76-
new_person = schema.load(person, session=db.session).data
76+
new_person = schema.load(person, session=db.session)
7777

7878
# Add the person to the database
7979
db.session.add(new_person)
8080
db.session.commit()
8181

8282
# Serialize and return the newly created person in the response
83-
data = schema.dump(new_person).data
83+
data = schema.dump(new_person)
8484

8585
return data, 201
8686

@@ -142,7 +142,7 @@ def update(person_id, person):
142142

143143
# turn the passed in person into a db object
144144
schema = PersonSchema()
145-
update = schema.load(person, session=db.session).data
145+
update = schema.load(person, session=db.session)
146146

147147
# Set the id to the person we want to update
148148
update.person_id = update_person.person_id
@@ -152,7 +152,7 @@ def update(person_id, person):
152152
db.session.commit()
153153

154154
# return updated person in the response
155-
data = schema.dump(update_person).data
155+
data = schema.dump(update_person)
156156

157157
return data, 200
158158

introduction-combining-data-pandas-merge-join-and-concat/climate_precip.csv

Lines changed: 151111 additions & 0 deletions
Large diffs are not rendered by default.

introduction-combining-data-pandas-merge-join-and-concat/climate_temp.csv

Lines changed: 127021 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)