Lecture 5: Tuples, Lists, Aliasing, Mutability, Cloning

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

Tuples

an immutable and ordered sequence of elements; element types can be mixed; represented with parentheses (); can perform indexing, concatenation, and len() on them

2
New cards

empty tuple

variable = ()

3
New cards

singleton tuple

tuple of one character/element

4
New cards

for loops with tuples

iterate over the tuple object at each position

5
New cards

Lists

ordered and mutable sequence of info/ elements that are usually homogenous, accessible by index; denoted by square brackets []; can index and len()

6
New cards

Iterating over a list

compute the sum of elements of a list; common pattern, iterate over list elements; indexed 0 to len(variable)-1 and range(n) goes from 0 to n-1

7
New cards

L.append(element)

add elements to end of list (mutates the list)

8
New cards

L.extend (some_list)

combines lists together

9
New cards

del(L[index])

delete element at a specific index

10
New cards

L.pop()

remove element at end of list and returns the removed element

11
New cards

L.remove (element)

removes a specific element’s 1st occurrence in a list (if not there then results in error)

12
New cards

list(s)

converts string to list by returning a list with every character from s with an element in L

13
New cards

s.split

splits a string on a character parameter, splits on spaces if called without a parameter

14
New cards

‘‘.join(L)

turn a list of characters into a string, can give a character in quotes to add char between every element

15
New cards

sorted()

returns sorted list, does not mutate (creates new list that must be assigned to new variable)

16
New cards

.sort()

mutates list by placing list elements in order (returns nothing)

17
New cards

.reverse()

mutates list by reversing order of list elements

18
New cards

alias

another variable name that gives same value as another variable (if one variable changes both changes)

19
New cards

List 1 = ListA[:]

clones a list by creating a new list and copy every element