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
¨C Multiple examples
2/28/2018
Matni, CS8, Wi18
3
Calculating Means and Medians Using Lists
? Mean (Average) = (max ¨C min) / sum
? Median (middle item) is more complex¡
¨C This isn¡¯t in any list function, so we have to develop it ourselves
Example:
1
5
2
10
8
7
7
6
3
8
10
sort it first and then find the middle value¡
1
2
3
5
6
7
7
Median = 6
If there¡¯s an even number of entities, then employ an average calc¡
1
2/28/2018
2
3
5
6
7
Matni, CS8, Wi18
7
8
Median = 5.5
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
- how to get keys of python dictionary as list tutorial kart
- ppyytthhoonn ddiiccttiioonnaarryy
- dictionaries store connections between pieces of list comprehensions a
- python tuple define access iterate
- cme193 introductiontoscientiï¬cpython lecture3 tuples sets
- beginners python cheat sheet pcc dictionaries anarcho copy
- python dictionary tutorial kart
- chapter 12 dictionary hash tables college of engineering
- dictionary case study gktcs
- chapter 2 lists arrays and dictionaries uc davis
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