Lists, Loops and Conditionals
[Pages:37]Lists, Loops and Conditionals
HORT 59000 Lecture 11
Instructor: Kranthi Varala
Core data types
? Numbers ? Strings ? Lists ? Dictionaries ? Tuples ? Files ? Sets
Lists
? A List is a general, sequence object where the individual items in the list can be different types. I.e., the same list can contain integers, floats, strings etc..
? Lists are mutable, i.e., a list can be changed without having to create a new list object
Lists: Common Methods
? L.append() : Adds one item to the end of the list. ? L.extend() : Adds multiple items to the end of the list. ? L.pop(i) : Remove item `i' from the list. Default:Last. ? L.reverse() : Reverse the order of items in list. ? L.insert(i,item): Inserts `item' at position i. ? L.remove(item) : Finds `item' in list and deletes it from the
list. ? L.sort(): Sorts the list in- place i.e., changes the sequence in
the list. (Sorting mixed data types only works on python2)
MultiDimensional Lists
? Lists are of arbitrary length and and easily be nested.
? Simplest nested lists are 2 ?dimensional matrices.
? my2DList = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]
my2DList
0
1
2
3
01 12 23 34
5
9
13
6
10
14
7
11
15
8
12
16
MultiDimensional Lists
? Nested Lists need not be homogeneous.
? my2DList = [[1,2,3,'a'],[5,6,7,'cat'],[9,10,'e',12],['beta',14,15,16]]
my2DList
0
1
2
3
01 12 23 3a
5
9
beta
6
10
14
7
e
15
cat
12
16
Arbitrary dimensional Lists
? Nested Lists need not be of the same length.
? my2DList = [[1,2,3,'a'],[5,6,7],[9,10,'e',12,'cat'],['beta',14,15,16]]
my2DList
0
1
2
3
01 12 23 3a
5
9
beta
6
10
14
7
e
15
12
16
cat
Arbitrary dimensional Lists
? Nested Lists can have arbitrary depth as well.
? subL = [['p','q'],['r','s']]
? my2DList = [[1,2,3,'a'],[5,6,7,'cat'],[9,10,'e',12],['beta',14,15,subL]]
my2DList
0
1
2
3
01 12 23 3a
5
9
beta
6
10
14
7
e
15
cat
12
0
1
0p
q
1r
s
................
................
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
- lecture 04 more iteration nested loops brown university
- evaluating nested expressions in python idc online
- list comprehensions department of computer science and electrical
- ppyytthhoonn nneesstteedd llooooppss
- chapter 3 selection statements southeastern louisiana university
- random access lists nested data types and numeral systems haskell
- lecture 6 lists nested loops and files github pages
- python if else and nested if else tutorial kart
- lecture 14 nested lists tuples and dictionaries
- about python 5 while loop
Related searches
- while loops in verilog
- lists of strengths and weaknesses examples
- dilated bowel loops icd 10
- ordered and unordered lists html
- free loops and sound kits
- home organization lists and charts
- dilated small bowel loops icd 10
- c lists and arrays
- lists of lists epa
- epa lists of lists excel
- preferred stock lists and prices
- lists of needs and wants