Pyton
[Python] Consider the following code segment. Which one of the following statements is correct? map(lambda x: x * 2, [1, 3, 4])
This function will double each element of [1, 3, 4]
[Python] Consider the following code segment. Which one of the following statements is correct? import random random.sample(range(10), 10)
This will generate a range of numbers from 0 to 9, listed in random order.
[Python] Which one of the following is correct given the code segment below? >>> A = ['a', 'b', 'c'] >>> B = ['1', '2', '3'] >>> all = [x + y for x in A for y in B] >>> print all
['a1', 'a2', 'a3', 'b1', 'b2', 'b3', 'c1', 'c2', 'c3']
[Python] Which one of the following is correct for this code segment run? >>> my_list = [x + 10 for x in range(3)] >>> my_list
[10, 11, 12]
[Python] Which one of the following examples uses a list comprehension to fill a list with powers of 2.
[2**x for x in range(1, 10)]
[Python] Consider a file "gm.py" listed below. Which of the following is incorrect to run this python file? #!/usr/bin/local/python print 'Good morning!' ./gm.py python gm.py python < gm.py cat gm.py | python echo gm.py | python
echo gm.py | python
[Python] One of the simplest re (for regular expression) methods is ___ returns a list that holds matches with a regular expression over a string.
findall
[Python] After a file is opened for read with a variable f (a file handle), which one of the following code segment is correct to read each line using for loop?
for line in f.readlines( ) : print(line)
[Python] Which one of the code segments makes each element of "items" to be squared, and printed?
for x in items : print(x*x)
[Python] Which one of the following builtin function is to apply a function (first argument) to each of the rest of the parameters?
map
[Python] Consider the following function definition. Which one is correct output? >>> def place_stuff(x = 10, y = 20, z = 30): return x, y, z >>> place_stuff(1,2,3)
(1, 2, 3)
[Python] Consider the following function definition. Which one is correct output? >>> def place_stuff(x = 10, y = 20, z = 30): return x, y, z >>> place_stuff()
(10, 20, 30)
[Python] Which one of the following statements is incorrect? Python supports Lambda functions. Lambda functions in Python might not be bound to a name. Lambda functions are referred to as anonymous functions. Lambda functions are more flexible than other functions because they can use an extensive functional features. In its most basic form, Lambda is another syntax for defining a function.
Lambda functions are more flexible than other functions because they can use an extensive functional features.
[Python] Which one of the following statements opens a file and returns a file object called a file handle
open('test_file', 'r')
[Python] The ___ module allows you to store an object in a file in a standard format for later use by the same or a different program.
pickle