Question

Python Write a move function that takes a list of tuples, where each tuple is an...

Python

Write a move function that takes a list of tuples, where each tuple is an x-y-z coordinate pair. This function should update the original list in-place to shift/move/translate the coordinates by an x_move, y_move, and z_move (respectively) and return None.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer

def move(pos, x_move, y_move, z_move):
    for i in range(len(pos)):
        pos[i] = (pos[i][0] + x_move, pos[i][1] + y_move, pos[i][2] + z_move)


pos = [(0, 0, 0), (1, 2, 3)]
move(pos, 10, 1, 0)
print(pos)  # [(10,1,0),(11,3,3)]



Please let me know if you have any doubts Please upvote this answer. Thanks!!

Add a comment
Know the answer?
Add Answer to:
Python Write a move function that takes a list of tuples, where each tuple is an...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple

    1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...

  • Language: Python Topic: Tuples Function name : todo_tuple Parameters : todo (list of tuples of strings),...

    Language: Python Topic: Tuples Function name : todo_tuple Parameters : todo (list of tuples of strings), completed (list of strings) Returns: final_list (list) Description : Write a function that takes in a list of tuples of strings that represents the work you have to do in each class, and a list of strings that represent the work you have already completed. Each tuple in the todo list represents the work for a single class. For this function, go through the...

  • Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e....

    Write function all_coprime_pairs( ) which takes as input a list, L, with positive unique integers (i.e. no duplicated integers), and should return: 1. List (of tuples) containing all pairs of numbers in L that are coprime. 2. Empty list, If no pair of numbers in L is coprime. Your solution must include a function call to the function coprime designed in the previous question. The order of the tuples or the order of the two numbers within the tuples is...

  • Write a function to find the smallest odd number in a list. The function takes a...

    Write a function to find the smallest odd number in a list. The function takes a list of numbers (each number is greater than or equal to 0) as an input. The function outputs a tuple, where the first number in the tuple is the smallest odd number and the second number in the tuple is the number of occurrences of that number. For example, if the input is [1, 4, 7, 3, 5, 2, 1, 3, 6] then the...

  • Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for...

    Python 5. Write a function named grade_components that has one parameter, a dictionary. The keys for the dictionary are strings and the values are lists of numbers. The function should create a new dictionary where the keys are the same strings as the original dictionary and the values are tuples. The first entry in each tuple should be the weighted average of the non-negative values in the list (where the weight was the number in the 0 position of the...

  • Language: PYTHON Function name : favorite_day Parameters : list of tuples (dates), int (weekday, 0-6, Mondays...

    Language: PYTHON Function name : favorite_day Parameters : list of tuples (dates), int (weekday, 0-6, Mondays are 0), int (day of the month 1 to 28) Returns: dates: list of tuples Description: Imagine that you have a favorite weekday, and want to see if certain days fall on that weekday. Using the calendar module from the Python standard library , write a function which takes in a list of tuples formatted like [(month, year), etc.], your favorite weekday, and a...

  • Define a function called collapse() which takes a list as input. Each element of the list...

    Define a function called collapse() which takes a list as input. Each element of the list will either be an integer, or a list of integers. The function should modify the input list by replacing all of the elements which themselves are lists with the sum of their elements. For example: Test Result vals = [1, 2, 3, 4, 5] collapse(vals) print(vals) [1, 2, 3, 4, 5] vals = [1, [2, 3], 4, 5] collapse(vals) print(vals) [1, 5, 4, 5]...

  • Version:0.9 StartHTML:0000000105 EndHTML:0000008229 StartFragment:0000000141 EndFragment:0000008189 In Python, a tuple is a collection similar to a list...

    Version:0.9 StartHTML:0000000105 EndHTML:0000008229 StartFragment:0000000141 EndFragment:0000008189 In Python, a tuple is a collection similar to a list in that it is an ordered collection of items. An important difference, however, is that a tuple is immutable – once created, a tuple cannot be changed. Also, tuples are denoted using parentheses instead of square brackets. As with lists, elements of a tuple are accessed using indexing notation. For example, given the tuple subjects = (’physics’, ’chemistry’, ’biology’), we could ac cess the...

  • in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all...

    in python A. Define a function called contains_only_integers() that takes a tuple, returns True if all the items in the tuple are integers(2), and returns False otherwise. For example, contains_only_integers (3, 5, 17, 257, 65537) ), contains_only_integers( (-1,) ), and contains_only_integers( ) should all return True, but contains_only_integers (2.0,4.0)) and contains_only_integers (8, 4, "2", 1)) should both return false. Your function should use a while loop to do this calculation. 121 Hint: the is instance() built-in function provides the most...

  • Write a python function that returns a list or array of tuples containing every permutation of...

    Write a python function that returns a list or array of tuples containing every permutation of numbers 1 to n. For example: permutate(1): [(1,)] permutate(2): [(1, 2), (2, 1)] permutate(3): [(1, 2, 3), (1, 3, 2), (3, 1, 2), (3, 2, 1), (2, 3, 1), (2, 1, 3)] #here is some starting code def permutate(n): result = [] return result

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT