You and your neighbor have equal sized gardens. Your gardens are represented as 2D-lists, where garden[i] [j] gives an element at position (i, j). Every element in a garden is represented as an string, and can be "grass", "moss", "strawberry" , "rock", "raspberry". Latley you have noticed more moss and rock in your garden and espects its to be your neighbor. To fix it, complete the function clean_mygarden(my_garden, neighbors_garden) At the end , swap every rock and moss in your garden with the first stawberry and raspberry from neighbor (they dont need to be at the same position MAKE A FUNCTION "find_items" that inputs two arguments: (garden, item) , and returns a (i, j) position as a tuple if item is in garden. If not, return None. Make a function swap_items that swaps two elements between two gardens. Let the function Input these arguments (garden1, garden2, pos1, pos2), where pos1 and pos2 is (i,j) tuples. def swap_items(garden1,garden2,pos1,pos2): Here you are not going to return something but change the lists you get as arguments. Use the functions you already defined to finish clean_garden(my_garden, neighbors_garden): Swap all rocks with strawberry and moss with raspberry from your neighbors garden as long as its possible to swap.
Python
You and your neighbor have equal sized gardens. Your gardens are represented as 2D-lists, where garden[i] [j] gives an element at position (i, j). Every element in a garden is represented as an string, and can be "grass", "moss", "strawberry" , "rock", "raspberry". Latley you have noticed more moss and rock in your garden and espects its to be your neighbor. To fix it, complete the function clean_mygarden(my_garden, neighbors_garden)
At the end , swap every rock and moss in your garden with the first stawberry and raspberry from neighbor (they dont need to be at the same position
MAKE A FUNCTION "find_items" that inputs two arguments: (garden, item) , and returns a (i, j) position as a tuple if item is in garden. If not, return None.
Make a function swap_items that swaps two elements between two gardens. Let the function Input these arguments (garden1, garden2, pos1, pos2), where pos1 and pos2 is (i,j) tuples.
def swap_items(garden1,garden2,pos1,pos2):
Here you are not going to return something but change the lists you get as arguments.
Use the functions you already defined to finish clean_garden(my_garden, neighbors_garden):
Swap all rocks with strawberry and moss with raspberry from your neighbors garden as long as its possible to swap.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images