Chapter 7: Tuples And Lists Flashcards

1
Q

A tuple is an ______ data type

A

Immutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Creating an empty type

A

Empty_tuple = ()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Make a tuple with one or more elements

A

One_marx = ‘Groucho’,
One_marx = (‘Groucho’,)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you have more than one element, follow all but the _____ one with a comma

A

Last

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is output
Marx_tuple = (‘Groucho’, ‘Chico’, ‘Harpo’)
A,b,c = marx_tuple
»>a
»>b
»>c

A

Groucho
‘Chico’
‘Harpo’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Marx_list = [‘Groucho’,’Chico’, ‘Harpo’]

Create a tuple using tuple()

A

Tuple(marx_list)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

You can combine tuple using ____

A

+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

You can duplicate items inside tuple using ____

A

*

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Tuple iteration uses the keyword _____

A

In

Ex:
For word in words:
Print(word)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

You _____ modify a tuple

A

Cannot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Lists in python are ______

A

Mutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Create a list in python

A

First_last_name = [‘Tanvi’, ‘Menkurkar’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the list() function do?

A

Converts other iterable data types (tuple, string, sets, dictionary) to lists.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Split()

A

Chops a string into a list by some separator

Ex:
Splitme = ‘a/b//c/d///e’
Splitme.split(‘/‘)
»>[‘a’,’b’,’ ‘, ‘c’, ‘d’, ‘’,’’,’e’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What if you have more than one separator in your original string?

A

You get an empty string as an list item

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to get an item in a list?

A

List_name[offset]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to get item from a list count from backward from the end?

A

Maxes[-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How to extract a subsequence of list

A

> > > Marxes[0:2]
[‘Groucho’,’Chico’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to reverse a list in python?

20
Q

How to add item to end of list?

21
Q

How to add item by offset with insert

A

List_name.insert(offset, item_name)

22
Q

How to duplicate all item in a list using_____

23
Q

How to combine lists

A

Option 1: extend()
Option 2: +

Ex:
Marxes += others
Marxes.extend(others)

24
Q

How to change item at a certain index?

A

List_name[offset] = new_item

25
Q

How to change a sub list in a list?

A

Slice
Numbers = [1,2,3,4]
Numbers[1:3] = [8,9]

> > > numbers
[1,8,9,4]

26
Q

How to delete an item in a list by offset?

A

Del marxes[-1]
Del marxes[1]

27
Q

Del is a python _____, not a list method

28
Q

Delete an item with remove()

A

Marxes.remove(‘Groucho’)

29
Q

How to delete an item (another way)

A

Pop(index)

31
Q

How to delete all items

32
Q

How to find an item’s offset by value

A

Marxes.index(‘Chico’)

33
Q

You can check if an item is in list using ___

A

In

‘Groucho’ in marxes

34
Q

Find the number of occurrences in a list

35
Q

Convert a list ot a string with ____

36
Q

The list method ____ sorts the list itself, in place

37
Q

The general function _____ returns a sorted copy of the list

A

Sorted() —> does not modify original list

38
Q

How to get length of list

39
Q

When you assign one list to more than one variable using ____, changing the list in one place also changes it in the other

40
Q

What are three ways to copy values of list to and independent, fresh list

A
  • the list copy() method
    The list() conversion function
  • THe list slice [:]
41
Q

How to compare lists

A

Using ===, <=, >= and so on

42
Q

How to iterate over multiple sequence in parallel

A

Zip() function

Ex:
For day,fruit,drink,dessert in zip(days,fruits,drinks, desserts):
Printf(….)

43
Q

Zip() stops when the _____ sequence is done

44
Q

How to build a list of integers from 1 to 5

A

Number_list = list(range(1,6))

45
Q

Another example

A

A_list = [number for number in range(1,60 if number %2 == 1]

46
Q

Can you create a list of lists