More Examples Using Lists Tuples and Dictionaries in Python - GitHub Pages
More Examples Using Lists Tuples and Dictionaries in Python
CS 8: Introduction to Computer Science, Winter 2018 Lecture #11
Ziad Matni Dept. of Computer Science, UCSB
Administrative
? Homework #6 is DUE on MONDAY (3/5) ? Lab #4 due Today! ? Project #2 will be issued by the end of the week
2/28/2018
Matni, CS8, Wi18
2
Lecture Outline
? 2 more example with lists...
? Tuples
? Dictionaries
? Multiple examples
2/28/2018
Matni, CS8, Wi18
3
Calculating Means and Medians Using Lists
? Mean (Average) = (max ? min) / sum ? Median (middle item) is more complex...
? This isn't in any list function, so we have to develop it ourselves
Example:
1 5 2 10 8 7 7 6 3
sort it first and then find the middle value...
1 2 3 5 6 7 7 8 10 Median = 6
If there's an even number of entities, then employ an average calc...
12356778
Median = 5.5
2/28/2018
Matni, CS8, Wi18
4
"Find the Median" Algorithm
1. Sort the list first 2. Determine the length of the list (why?) 3. Find the middle of the list (length/2)
a) If the length is an odd number, then there's only 1 middle
b) If the length is an even number, then identify the middle 2 and get their average
2/28/2018
Matni, CS8, Wi18
5
................
................
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
- sample of university of michigan shool of information masters of
- programming with python lists tuples and dictionaries schoolnova
- python lesson 4 dictionaries
- computer science principles stony brook university
- chapter 9 python dictionary
- chapter 2 lists arrays and dictionaries
- python cheat sheet california state university stanislaus
- solving anagrams no starch press
- lambdas and custom sort stanford university
- cs5001 cs5003 intensive foundations of computer science lecture 5
Related searches
- using and twice in a sentence
- list of dictionaries in python
- creating a list of dictionaries in python
- join in python using on
- create a matrix in python using for
- integration in python using numpy
- dictionaries in spanish
- compound sentences examples using for
- dictionaries in python
- for loop in python using range
- dictionaries in python 3
- building tables in python using matplotlib