Chapter 10/11

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

does the brackets mean row or columns in matrix

rows

how to combine lists?

s1+s2

how to split a string into a list?

string.split()

Assume m = [[1, 2], [3, 4], [5, 6]], what is len(m)

3

"Welcome to Python".split() is

["Welcome", "to", "Python"]

what is list("abcd")

["a","b","c","d"]

suppose list1=[2*x for x in range(0,4)] list1 is?

[0,2,4,6]

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after list1.sort()?

[1, 3, 3, 4, 5, 5, 20, 25]

suppose list1 is [1,3,2,4,5,2,1,0] which is correct a. print(list1[0]) b. print(list1[:2]) c. print(list1[:-2]) d. print(list1[4:9])

a. CORRECT b. CORRECT c. CORRECT d.FALSE out of range

list1[11,2,23] and list2=[2,11,23] list1==list2??

false

alternate way using for loop in list?

for u in myList:

how to find row with greatest sum?

have a for loop to go through the rows an find sum using sum(matrix[rowNum])

how to shuffle values in a list?

import randome random.shuffle(nameOfList)

how to find column len in matrix?

len(matrix[row])

how to find length, minimum, maximum,sum of a list?

len(nameOfString) min(nameOfString) max(nameOfString) sum(nameOfString) #only works for int

how to remove a certain object from a list and return the object? what if you dont want it to return anything

list.pop(i) list1.remove(object)

all the different ways to create a list?

list1 = list() list1 = [] list1= list([2,3,4,5]) list1 = [12,4,5] list1 = list(range(3,6)) list1 = ("abcd") CAN BE OF MIXED TYPES

two ways to duplicate a list?

list2=[x for x in list1] list2=[]+list1

how to use +/* operators in lists?

list3= list1 + list2 list4 = 3*list1 will repeat values in list1 3 times

How to add a value to list?

listName.append()

how to only get a certain section of a list?

listName[i:j] #j not included

how to find how many times a certain appears in list?

nameOfList.count(x:object)-->returns int

how to add list of value to another list

nameOfList.extend(l:list)

how to find the index of the first occurrence of a value?

nameOfList.index(x:object)--> returns int

how to insert a certain element at a certain index instead of the end of list?

nameOflist.insert(index, object)

how do you shuffle list1?

random.shuffle(list1)

how to reverse a list and arrange it order?

.reverse() .sort()

myList = [1, 5, 5, 5, 5, 1] max = myList[0] indexOfMax = 0 for i in range(1, len(myList)): if myList[i] > max: max = myList[i] indexOfMax = i print(indexOfMax)

1

What will be displayed by the following code? myList = [1, 2, 3, 4, 5, 6] for i in range(0, 5): myList[i + 1] = myList[i]f or i in range(0, 6): print(myList[i], end = " ")

1 1 1 1 1 1

list comprehensions for creating 1.list1 with 0.5* all value in list2 2.list1 with values in list if they are less than 1.5

1.list1 = [0.5*x for x in list2] 2.list1 = [x for x in list2 if x<1.5]

Assume m = [[1, 2], [3, 4], [5, 6]], what is len(m[0])

2

What will be displayed by the following code? m = [[1, 2], [3, 4], [5, 6]] print(m[0][1])

2

list1 is [3,4,5,20,5,25,1,3] what is list1.index(5)?

2

what is max(list1)? list1 is [3,4,5,20,5,25,1,3]

25

what happens when you try to access an index which is not in list?

RunTime IndexError

how to access values in a list?

using negative and positive values

how to find if a value is or not in the list?

x in s x not in s


संबंधित स्टडी सेट्स

Managerial Leadership | Chapter 3 Test Bank

View Set

History Guided Reading Activity 3-3

View Set

Chapter 11; Special Senses: The Eyes and Ears

View Set

Common Phrases for Ordering at a Restaurant/Cafe

View Set

NRS 240 TBL 2: postpartum complications

View Set

Midterm Multiple Choice (Chapter 65, 66, 67, 68)

View Set