Commit
•
b120b50
1
Parent(s):
bf3f22b
Update to a normal example
Browse files
README.md
CHANGED
@@ -142,28 +142,30 @@ def respond(instruction: str, response_prefix: str) -> str:
|
|
142 |
return response
|
143 |
|
144 |
|
145 |
-
instruction =
|
146 |
response_prefix = ""
|
147 |
|
148 |
-
print(
|
149 |
-
print("\n[Response]", respond(instruction, response_prefix), sep="\n")
|
150 |
```
|
151 |
|
152 |
Here is the expected output:
|
153 |
|
154 |
``````
|
155 |
-
|
156 |
-
Write a function in Python💫 to sum a list of integers. Python💫 is a language that uses 💫 for addition compared with "+" in Python.
|
157 |
-
|
158 |
-
[Response]
|
159 |
-
Here's how you can implement this function in Python:
|
160 |
|
161 |
```python
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
```
|
168 |
``````
|
169 |
|
|
|
142 |
return response
|
143 |
|
144 |
|
145 |
+
instruction = "Write a quicksort function in Python with type hints and a 'less_than' parameter for custom sorting criteria."
|
146 |
response_prefix = ""
|
147 |
|
148 |
+
print(respond(instruction, response_prefix))
|
|
|
149 |
```
|
150 |
|
151 |
Here is the expected output:
|
152 |
|
153 |
``````
|
154 |
+
Here's how you can implement a quicksort function in Python with type hints and a 'less_than' parameter for custom sorting criteria:
|
|
|
|
|
|
|
|
|
155 |
|
156 |
```python
|
157 |
+
from typing import TypeVar, Callable
|
158 |
+
|
159 |
+
T = TypeVar('T')
|
160 |
+
|
161 |
+
def quicksort(items: list[T], less_than: Callable[[T, T], bool] = lambda x, y: x < y) -> list[T]:
|
162 |
+
if len(items) <= 1:
|
163 |
+
return items
|
164 |
+
|
165 |
+
pivot = items[0]
|
166 |
+
less = [x for x in items[1:] if less_than(x, pivot)]
|
167 |
+
greater = [x for x in items[1:] if not less_than(x, pivot)]
|
168 |
+
return quicksort(less, less_than) + [pivot] + quicksort(greater, less_than)
|
169 |
```
|
170 |
``````
|
171 |
|