Sorting: Thinking about Algorithms - Purdue University
Sorting: Thinking
about Algorithms
HORT 590
Lab 12
Instructor: Kranthi Varala
Sorting a list of values
? Sorting is the process of ordering items in an
increasing (or decreasing) order based on their
value.
? Lists in Python can be sorted in two ways:
? list.sort() function
? sorted() function
? sorted is a general function that will accept any
iterable item, such as dictionaries, tuples etc.
? Both versions use a sorting algorithm called
¡®Timsort¡¯ which is a hybrid of merge and insert
sort methods.
Sorting a list of values
? Remember to capture the output of sorted in a
new object
Sorting tuples
? Sorting tuples by default will sort them by the first
element in the tuple. In this example, that is the name
of the employee.
? The sorted() function can be used to sort based on a
different element by using the ¡®key¡¯ argument.
? In this example, the lambda construct is used to
generate an inline functions that simply returns the
element at index 2.
Sorting Dictionaries
? Sort by keys :
? Sort by values :
? Sort keys by values :
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- sarge documentation read the docs
- accessing the pps near real time data using https
- sorting thinking about algorithms purdue university
- sarge documentation
- basic 9 python
- part 1 regular expressions regex
- cis192 python programming
- python pipelines massachusetts institute of technology
- intuitive python the pragmatic programmer
- python 3 child processes
Related searches
- what states are thinking about legalizing pot
- is he thinking about me too
- is he thinking about me
- is he thinking about me quiz
- constantly thinking about someone
- thinking about you quotes
- someone is thinking about me
- is someone thinking about me
- signs he s thinking about me
- signs someone is thinking about you
- sensing someone thinking about you
- why can t i stop thinking about someone