-
Notifications
You must be signed in to change notification settings - Fork 0
не понятно #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
не понятно #146
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Реализовать алгоритм сортировки от мин к макс | ||
| def mini(s): # функц поиск минимального значения | ||
| min_num = float('inf') # минимальное значение почему-то +бесконечность?! | ||
| min_idx = 0 # минимальный индекс | ||
| for index, items in enumerate(s): # сотировака списка энумерэйт индекс, значение | ||
| if items < min_num: # Если значение меньше минимального значение | ||
| min_num = items # то минимальное значение = значению из списка | ||
| min_idx = index # и его индекс = индексу минимального значения | ||
| return min_idx, min_num # нишли и вернули мин значение и его индекс | ||
|
|
||
| def sort_min(x): # функция сортировки | ||
| i = 0 | ||
| while i < len(x): | ||
| min_idx, min_num = mini(x[i:]) # почему функц мини накидываем на срез? | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Потому что список x до i уже отсортирован и содержит минимальные значения. |
||
| if min_idx != 0: | ||
| x[i], x[min_idx + i] = x[min_idx + i], x[i] # какое i добавляется? | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. min_idx - это относительный индекс в срезе. |
||
| i += 1 | ||
| return x | ||
|
|
||
|
|
||
| a = [0,3,24,2,3,7] | ||
| d = sort_min(a) | ||
| print(d) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| def fun(x): | ||
| for i in range(len(x)): | ||
| for j in range(i): | ||
| if x[i] == x[j]: | ||
| return x[i] | ||
|
|
||
|
|
||
| lst1 = [2, 3, 4, 5, 3, 2] | ||
| print(fun(lst1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Изначально, пока мы не начали смотреть строку, у нас нет какого-либо минимального значения. А сравнивать items уже с чем-то надо (стр.6).
+бесконечность - значение, больше которого заведомо не будет - при первом же сравнении заменится на начальный элемент в s.