List Flashcards

1
Q

t = [“d”,”c”,”e”,”b”,”a”]
t.sort()
t

A

[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]

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

t = [“a”,”b”,”c”]
t.append(“d”)
t

A

[‘a’, ‘b’, ‘c’, ‘d’]

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

t1 = [“a”,”b”,”c”]
t2= [“d”,”e”]
t1.extend(t2)
t1

A

[‘a’, ‘b’, ‘c’, ‘d’, ‘e’]

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

t=[“a”,”b”,”c”,”d”,”e”,”f”]
t[1:3] = [“x”,”y”]
t

A

[‘a’, ‘x’, ‘y’, ‘d’, ‘e’, ‘f’]

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

t = [“a”,”b”,”c”,”d”,”e”,”f”]
t[:]

A

[‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’]

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

t = [“a”,”b”,”c”,”d”,”e”,”f”]
t[1:3]

A

[‘b’, ‘c’]

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

t = [“a”,”b”,”c”,”d”,”e”,”f”]
t[:4]

A

[‘a’, ‘b’, ‘c’, ‘d’]

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

t = [“a”,”b”,”c”,”d”,”e”,”f”]
t[3:]

A

[‘d’, ‘e’, ‘f’]

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

[1,2,3]*3

A

[1, 2, 3, 1, 2, 3, 1, 2, 3]

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

[0] *4

A

[0, 0, 0, 0]

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

a = [1,2,3]
b = [4,5,6]
c = a+b
c

A

[1, 2, 3, 4, 5, 6]

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

number=[42,5]
for i in range(len(number)):
number[i] = number[i] * 2

print(number)

A

[84,10]

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

number=[42,5]

42 in number
123 in number
5 in number

A

TRUE
FALSE
TRUE

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

for cheese in cheeses:
print(cheese)

A

Cheddar
Edam
Gouda

Wil print without []

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

t = t.sort()
t

A

Return None and modify the List to empty list and if you try again you’ll get none type error because you are sorting empty list.

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

t = [1,2,3]
sum(t)

A

6

17
Q

def capitalize_all(t):
res = []
for s in t:
res.append(s.capitalize())
return res
capitalize_all([“vishal”,”sehgal”])

Also,
What if we write last line without list like: capitalize_all(“vishal”,”sehgal”)

A

[‘Vishal’, ‘Sehgal’]

Error

18
Q

.capitalize()

A

Capital 1st letter

19
Q

.upper()

A

Capital Everything

20
Q

.isupper()

A

Return True or False according to String.
This is not .upper which turn everything CAPITALISE

21
Q

def only_upper(t):
res = []
for s in t:
if s.isupper():
res.append(s)
return res
only_upper([“vishal”,”sehgal”])

A

[]
Empty List

22
Q

t = [“a”,”b”,”c”]
x = t.pop(1)
t
x

A

[‘a’, ‘c’]

‘b’

23
Q

t= [“a”,”b”,”c”]
t.remove(“b”)
t

Will this work on index

A

[‘a’, ‘c’]

No, it only remove string

24
Q

t = [“a”,”b”,”c”]
del t[1]
t

Will this work on String

A

[‘a’, ‘c’]

No, it only remove index

25
Q

t = [“a”,”b”,”c”,”d”,”e”,”f”]
del t[1:5]
t

A

[‘a’, ‘f’]

26
Q

s = “spam”
t = list(s)
t

A

[’s’, ‘p’, ‘a’, ‘m’]

27
Q

s =”spam dog “
t = s.split()
t

What if we put s in split like s.split(s)

A

[‘spam’, ‘dog’]

[’’, ‘’]

28
Q

t = [“pining”, “for”,”the”,”fjords”]
delimeter = “ “
s = delimeter.join(t)
s

A

‘pining for the fjords’

29
Q

s = “spam-spam-spam”
delimiter = “-“
t = s.split(delimiter)
t

A

[‘spam’, ‘spam’, ‘spam’]

30
Q

t= [“1”,”2”,”3”,”5”,”6”,”7”]
delimeter = “ “
s = delimeter.join(t)
s

A

‘1 2 3 5 6 7’

31
Q

a = [1,2,3]
b = [1,2,3]
a is b

A

False

32
Q

a = “banana”
b = “banana”
a is b

A

True

33
Q

a = [1,2,3]
b = a
b is a

A

True

34
Q

`a = [1,2,3]
b[0] = 42
a

A

[42, 2, 3]

35
Q

def delete_head(t):
del t[0]
letter = [“a”,”b”,”c”]
delete_head(letter)
letter

A

[‘b’, ‘c’]

36
Q

t1 = [1,2]
t2 = t1.append(3)
t1

What will t2 do?

A

[1, 2, 3]

None

37
Q

t1 = [1,2]
t3 = t1 +[4]
t1 =
t3 =

A

t1 = [1,2,3]
t2 = [1,2,3,4]