Take as many assements as you can to improve your validate your skill rating
Total Questions: 20
1. What is the output of the list comprehension shown below?
[j for i in range(2,8) for j in range(i*2, 50, i)]
Correct Answer is : A list of non prime numbers, up to 50
2. What is the output of the code shown below?
l=["good", "oh!", "excellent!", "#450"]
[n for n in l if n.isalpha() or n.isdigit()]
Correct Answer is : [‘good’]
3. Which of the following commands will create a list?
Correct Answer is : all of the mentioned
4. What is the output when we execute list(“hello”)?
Correct Answer is : [‘h’, ‘e’, ‘l’, ‘l’, ‘o’].
5. Suppose listExample is [‘h’,’e’,’l’,’l’,’o’], what is len(listExample)?
Correct Answer is : 5
6. Suppose list1 is [2445,133,12454,123], what is max(list1) ?
Correct Answer is : 12454
7. Suppose list1 is [3, 5, 25, 1, 3], what is min(list1) ?
Correct Answer is : 1
8. Suppose list1 is [1, 5, 9], what is sum(list1) ?
Correct Answer is : 15
9. To shuffle the list(say list1) what function do we use ?
Correct Answer is : random.shuffle(list1)
10. Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation ?
Correct Answer is : all of the mentioned
11. Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1] ?
Correct Answer is : 25
12. Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1] ?
Correct Answer is : [2, 33, 222, 14].
13. What is the output when following code is executed ?
>>>names = ['Amir', 'Bear', 'Charlton', 'Daman']>>>print(names[-1][-1])
Correct Answer is : n
14. What is the output when following code is executed ?
names1 = ['Amir', 'Bear', 'Charlton', 'Daman']names2 = names1names3 = names1[:] names2[0] = 'Alice'names3[1] = 'Bob' sum = 0for ls in (names1, names2, names3): if ls[0] == 'Alice': sum += 1 if ls[1] == 'Bob': sum += 10 print sum
Correct Answer is : 12
15. Suppose list1 is [1, 3, 2], What is list1 * 2 ?
Correct Answer is : [1, 3, 2, 1, 3, 2] .
16. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is :
Correct Answer is : [0.0, 0.5, 1.0, 1.5].
17. What is the output when following code is executed ?
>>>list1 = [11, 2, 23]>>>list2 = [11, 2, 2]>>>list1 < list2 is
Correct Answer is : FALSE
18. To add a new element to a list we use which command ?
Correct Answer is : list1.append(5)
19. To insert 5 to the third position in list1, we use which command ?
Correct Answer is : list1.insert(3, 5)
20. To remove string “hello” from list1, we use which command ?