Question

In Python, write a function that takes in an arbitrary list of numeric triples (tuples of...

In Python, write a function that takes in an arbitrary list of numeric triples (tuples of size 3), and returns a new list containing the maximum elements from each

Homework Answers

Answer #1

Explanation is in comments wherever needed.

First I have simply written program to print list of max element from each tuple from better understanding.

Then I have written a function as you asked for in the question.

Code:

# List of tuples

listTuples = [(1, 2, 3), (3, 4, 5), (5, 6, 4), (6,5,8), (4,8,5), (5,8,2)]

  

# initialization of required result list

result = []

# iterating over the list of tuples

for tup in listTuples :

    # temporary variable t to store max element

    t = max (tup) #max function to find the max value

    result.append(t) # append max value in the list

  

# printing output

print(result)

#implemantation using function

def listMax(listTup):

    # initialization of required result list

    result = []

    # iterating over the list of tuples

    for tup in listTuples :

        # temporary variable t to store max element

        t = max (tup) #max function to find the max value

        result.append(t) # append max value in the list

    

    # returning teh list of max of tuples

    return result

# List of tuple

listTuples1 = [(1, 2, 3), (3, 4, 5), (5, 6, 4), (6,5,8), (4,8,5), (5,8,2)]

# invoking listMax function to get list of max of each tuples

listMax1 = listMax(listTuples1)

# Print the list got from the function

print(listMax1)

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 Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function to count the number of even numbers from a list of numbers....
Write a Python function to count the number of even numbers from a list of numbers. Write a Python function that takes a list and returns a new list with unique elements of the first list. Sample List : [1,2,3,3,3,3,4,5] Unique List : [1, 2, 3, 4, 5]
Function name : matrixMultiplication Parameters : aMatrix (list), bMatrix (list) Returns Type: list of tuples Description...
Function name : matrixMultiplication Parameters : aMatrix (list), bMatrix (list) Returns Type: list of tuples Description : Write a function in PYTHON that takes in two matrices (list of tuples or list of lists) and multiplies the two matrices together. Assume that the given matrices will be valid, i.e. aMatrix will be n x m (n rows and m columns) and bMatrix will be m x ℓ (m rows and ℓ columns). *Assume elements of aMatrix & bMatrix will be...
[Python] Write a function named "total_population" that takes a string then a list as parameters where...
[Python] Write a function named "total_population" that takes a string then a list as parameters where the string represents the name of a CSV file containing city data in the format "CountryCode,CityName,Region,Population,Latitude,Longitude" and the second parameter is a list where each element is itself a list containing 3 strings as elements representing the CountryCode, CityName, and Region in this order. Return the total population of all cities in the list. Note that the city must match the country, name, and...
In Python: Problem 5] Write a function that accepts a list as argument and returns a...
In Python: Problem 5] Write a function that accepts a list as argument and returns a list that contains: (1) The positive elements of the taken list (2) The negative elements of the taken list (3) The odd elements of the taken list (4) The even elements of the taken list
Write a Python function first_chars that takes one parameter, which is a nested list of strings....
Write a Python function first_chars that takes one parameter, which is a nested list of strings. It returns a string containing the first character of all of the non-empty strings (at whatever depth they occur in the nested list) concatenated together. Here are a couple of examples of how the function should behave when you're done: >>> first_chars(['Boo', 'is', 'happy', 'today']) 'Biht' >>>first_chars(['boo', 'was', ['sleeping', 'deeply'], 'that', 'night', ['as', ['usual']]]) 'bwsdtnau'
Python Write function words() that takes one input argument—a file name—and returns the list of actual...
Python Write function words() that takes one input argument—a file name—and returns the list of actual words (without punctuation symbols !,.:;?) in the file. >>> words('example.txt') ['The', '3', 'lines', 'in', 'this', 'file', 'end', 'with', 'the', 'new', 'line', 'character', 'There', 'is', 'a', 'blank', 'line', 'above', 'this', 'line']
Python pls create a function called search_position. This function returns a list of 2 tuples and...
Python pls create a function called search_position. This function returns a list of 2 tuples and the number should be start highest number. The first index is the number, and second are list of 2 tuples that sorted by position in alphabetical order: The first index will be position and second index will be champion's name(This also should be sorted by alphabetical order). team1 = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2,...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT