Question

Define a function getSeconds() that accepts one argument: a list of lists. getSeconds() should return the...

Define a function getSeconds() that accepts one argument: a list of lists. getSeconds() should return the second item in every sublist that has at least two items. If the sublist has fewer than two items, it should be ignored. For example:

getSeconds([[1,2], ['a', 'b', 'c'], ['x'], [10, 20]]) should be [2, 'b', 20]

Homework Answers

Answer #1

Here is the required solution in python language

here is the code

#function defination
def getSeconds(lis):
l=[]
for x in lis:
if len(x)>=2:
l.append(x[1])
return l
  
#test case
print(getSeconds([[1,2],['a','b','c'],['x'],['10','20']]))

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a LISP function that accepts two lists as it's only arguments. The function should return...
Write a LISP function that accepts two lists as it's only arguments. The function should return a new list with the arguments as it's elements. So, if you pass the function (a b c) and (1 2 3), the function should return ((a b c) (1 2 3)).
In Python: Sublist of list A is defined as a list whose elements are all from...
In Python: Sublist of list A is defined as a list whose elements are all from list A. For example, suppose list A = [0, 1, 2, 3, 4, 5, 6], its has many sublists and one of them is [0, 1, 3] because elements 0, 1 and 3 are all contained in list A. Define a function named returnComplement that accepts two integer lists as the parameter (one of the list is the sublist of the other). Suppose names...
Define a function createPhonebook that accepts three arguments: A list of first names A list of...
Define a function createPhonebook that accepts three arguments: A list of first names A list of last names A list of phone numbers All three arguments will have the same number of items. createPhonebook should return a dictionary where the keys are full names (first name then last name) and the values are phone numbers. For example: firstNames = ['Jay', 'Daisy', 'Nick', 'Myrtle'] lastNames = ['Gatsby', 'Buchanan', 'Carraway', 'Wilson'] phones = ['5551212', '4441234', '4568309', '1456871'] phonebook = createPhonebook(firstNames, lastNames, phones)...
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most...
Write the function most_factors(numbers) that returns the integer from the list numbers that has the most factors (divisors without remainder). For example: >>> most_factors([5,10,16,20,25]) 20 # because 20 has the most factors of any of these numbers # 6 factors, i.e., [1, 2, 4, 5, 10, 20] >>> most_factors([1, 2, 3, 4, 5]) 4 # because 4 has the most factors of any of these numbers # 3 factors, i.e., [1, 2, 4] Hints: For each element in numbers, call...
Define and test a function myRange. This function should behave like Python’s standard range function, with...
Define and test a function myRange. This function should behave like Python’s standard range function, with the required and optional arguments, but it should return a list. Do not use the range function in your implementation! Study Python’s help on range to determine the names, positions, and what to do with your function’s parameters. Use a default value of None for the two optional parameters. If these parameters both equal None, then the only provided argument should be considered the...
Write a function that accepts an int array and the array’s size as arguments. The function...
Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N...
python pls Create function math_life() this function takes one or more argument. If this function called...
python pls Create function math_life() this function takes one or more argument. If this function called with no argument, raise typeError. The math_life() function returns to a function defined inside. this will take a one argument. For the second argument, it will calculate second function passed to math_life(). You should assume that the math_life() passed x functions, when it called the x times it will calculate the xth function passed to math_life() arguments when it called x+1 time it again...
assume you are in main.cpp define a function that is NOT SCOPED to any class. It...
assume you are in main.cpp define a function that is NOT SCOPED to any class. It is NOT a member of the ListInterface nor LinkedList classes. Your function should accept two lists. You will remove all values from the first list that are present in the second list. Example: Lists before call:                                                          Lists after call: target: A, B, C, A, D, C, E, F, B, C, A                        target: A, A, D, E, F, A toRemove: C, B, Q,...
Python: Working with CSV file --> How would I write a function that will return a...
Python: Working with CSV file --> How would I write a function that will return a list of lists, with the frequency and the zip code. Organize the list in decreasing order of frequency (Print the number of suppliers and the zip code for the 10 most common zip codes in the file. ) An example of three items from the 720 zip codes results in: [ ... [9, '65616'], [8, '94573'], [8, '63103'] ...]. This tells us that Branson,...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n,...
Problem 2: Python 3 Implement a function called gee_whiz that does the following: given argument n, a positive integer, it returns a list of n tuples corresponding to the numbers 1 through n (both inclusive): the tuple for the number k consists of k as the first component, and exactly one of the following strings as the second: • the string 'two!' if k is divisible by 2 • the string 'three!' if k is divisible by 3 • the...