Sequences & Lists
- sequence : an ordered collection of values
- list : a sequence of values of any data type
List Basics
- lists are denoted by []
- features of lists:
( index ) : a position of an element in a list
: starts from 0 goes to (length -1)
:use list_name[index] to find the element in that index
For loops
- similar to while loops
python codes ex.
def while_print_list(lst):
index = 0
while index < len(list)
print(lst[index])
index += 1
def for_print_list(lst):
for elem in lst:
print(elem)
List comprehension
- compact way to create a list
python codes ex.
result = []
for elem in lst:
if elem > 3:
result += [elem + 1]
[elem+1 for elem in lst if elem > 3]
elem + 1 : output adding to the resulting list
lst : sequence we're iterating through
if elem > 3 : (optional) condition
Data Abstractions
- treating codes as objects
- you do not have to know how the code is implemented you just have to know what it does
- data abstracted values are called Abstract Data Type
- comprehension of data abstraction
: constructors _ create ADT
: selectors _ select values from ADT
'University of California, Berkeley > ElectricalEngineering & ComputerSciences' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
Trees (0) | 2019.07.11 |
---|---|
Functional Decomposition & Debugging (0) | 2019.07.10 |
Sequence & Data Abstraction (0) | 2019.07.09 |
Week 3 (0) | 2019.07.09 |
LAB_day 3 (0) | 2019.07.04 |