Тёмный
No video :(

Exercise - Write a Sorting Function 

Khan Academy
Подписаться 9 млн
Просмотров 63 тыс.
50% 1

Challenge to write a Python function that can sort a list in-place

Опубликовано:

 

5 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 14   
@parkamark
@parkamark 13 лет назад
@heyandy889 I mostly agree with you. However, a function by definition returns a value or object. A subroutine doesn't. As it turns out, all functions and methods in Python return the object 'None', if no explicit 'return' statement is used within the function or method to return something. So in Python terms, they are the same thing. The intention of my comment was to highlight the semantic difference between both, within the realms of imperative and object orientated language paradigms.
@parkamark
@parkamark 13 лет назад
@JeremyNasmith min() returns the minimum value from a list/set, yes. The code is short, but it is far from efficient. Python takes the niceties out of having to traverse arrays/lists by hiding all the real work from the coder (when you call min() on a list, it's having to go away and call a lengthy subroutine to work this out). Based on the data structures Python uses to store lists/sets etc, this will normally be pretty fast, most times. As for Lambda functions, Google is your friend.
@rockingamingwiththesahit2145
@rockingamingwiththesahit2145 4 года назад
👍👍👍👍
@heyandy889
@heyandy889 13 лет назад
@parkamark "function" and "method" mean almost the same thing. Another synonym is "subroutine."
@parkamark
@parkamark 13 лет назад
a.sort() is not a function, it is a method which operates on list objects. But I appreciate what you are saying about a.sort() being in-line. My attempt at sorting a list without using in-built Python sort (non in-line) is this (yes, it is the most naive sorting algorithm but it works): def my_remove(l,v): l.remove(v) return l my_sort = lambda l: l and [min(l)] + my_sort(my_remove(l,min(l))) my_sort([7,3,5,9,3,5,45,1,3,764745,42354,3]) [1, 3, 3, 3, 3, 5, 5, 7, 9, 45, 42354, 764745]
@thelight9492
@thelight9492 Год назад
Methods are functions within a class.
@jreylbc1
@jreylbc1 13 лет назад
YES YES MORE CS MORE CS!!!!
@JeremyNasmith
@JeremyNasmith 13 лет назад
@parkamark Nice concise code: but for us noobs: what is lambda in python? And I suppose min(l) returns the smallest/first value in list l? if min works this way, it's a very nice solution for having to traverse the list, and remember progressively smaller encountered values...
@AQWorldAceChronozap
@AQWorldAceChronozap 13 лет назад
and first view
@parkamark
@parkamark 13 лет назад
@AkrionXxarr My comments are in relation to Python, not C/C++. Interestingly, you have written, and I quote, 'a function of type void doesn't return anything' - well, it does, doesn't it? It returns an object, of type 'void'. Python returns objects of type 'None'. WikiPedia: 'The void type, in several programming languages derived from C and Algol68, is the type for the result of a function that returns normally, but does not provide a result value to its caller.' ... ???
@Kramer7969
@Kramer7969 13 лет назад
Somebody should write a function to sort the comments, the first comment is in the second spot! :)
@marcportugal1
@marcportugal1 13 лет назад
Khan Rules
@AQWorldAceChronozap
@AQWorldAceChronozap 13 лет назад
FIRST COMMENT
@lifeDotGov
@lifeDotGov 13 лет назад
fourth
Далее
Insertion Sort Algorithm
7:52
Просмотров 206 тыс.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Cristiano Ronaldo Surpassed Me! #shorts
00:17
Просмотров 8 млн
Throwing Swords From My Blue Cybertruck
00:32
Просмотров 10 млн
All Python Syntax in 25 Minutes - Tutorial
24:59
Просмотров 37 тыс.
How To Use Functions In Python (Python Tutorial #3)
14:55
Stepping Through Insertion Sort Function
11:55
Просмотров 38 тыс.
Insertion Sort in Python
8:36
Просмотров 163 тыс.
The hardest problem on the hardest test
11:15
Просмотров 15 млн
Winning Facebook (Meta) Hacker Cup Qual Round 2022?
53:55
Solving Wordle using information theory
30:38
Просмотров 10 млн