1a and b 3-4 pictures are the templete
Posted: Fri Jul 01, 2022 5:52 am
1a and b
3-4 pictures are the templete
I will carefully check things like L is unaffected by the function call and None is returned. 1. (a) def compare_val_w_idx (L): """Compares each value of a list of numbers with its index... L is unaffected by the function call. The function returns a list M of the same length as L. M is 1 when L is bigger than i, M is -1 when L is less than 1, M[1] is 0 when L is equal to 1. www pass Test: L [4,5,6,3,4,5,2,3,4] print (compare_val_w_idx (L)) should print [1, 1, 1, 0, 0, 0, -1, -1, -1]. 1
(L): "Compares each value of a list of numbers with its index... (b) def compare_val_w_idx_no_obj No new objects (except ints) are created during the function call!! None is returned, but L is mutated by the function call. For any list of numbers L, the following code results in True being printed. M compare_val_v_idx (L) compare_val_w_idx_no_obj (L) print (LM) So L is mutated to the return value of compare_val_w_idx (L). HER pass Test: L [4,5,6,3,4,5,2,3,4] compare_val_v_idx_no_obj (L) print (L) should print (1, 1, 1, 0, 0, 0, -1, -1, -1]. "No new objects" means that you should not be creating any new lists. For example, def compare_val_v_idx_no_obj (L): M L.clear() compare_val_v_idx (L) L. extend (M) is NOT an okay solution. (For the pedantic, I'm not counting range (len (L)) as an object even though it is. You're fine to use this.)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- |||||| Created on Sun Mar 27 00:00:00 2022 @author: sarahburnett #%% 1A def compare_val_w_idx (L): """Compares each value of a list of numbers with its index... L is unaffected by the function call. The function returns a list M of the same length as L. M is 1 when L is bigger than i, M is -1 when L is less than i, M is 0 when L[i] is equal to 1. 111111 pass #%% 1B def compare_val_w_idx_no_obj (L): """Compares each value of a list of numbers with its index... No new objects (except ints) are created during the function call!! None is returned, but L is mutated by the function call. For any list of numbers L, the following code results in True being printed. M = compare_val_w_idx (L) compare_val_w_idx_no_obj (L) print (L == M)
M[i] is 1 when L[i] is bigger than i, M[i] is -1 when L[i] is M[ij is o when L[ij is less than i, equal to i. HR pass # % % 1B def compare_val_w_idx_no_obj (L): """Compares each value of a list of numbers with its index... nin No new objects (except ints) are created during the function call!! None is returned, but L is mutated by the function call. For any list of numbers L, the following code results in True being printed. M compare_val_w_idx (L) compare_val_w_idx_no_obj (L) print (L == M) So L is mutated to the return value of compare_val_w_idx(L). |||||| pass
3-4 pictures are the templete
I will carefully check things like L is unaffected by the function call and None is returned. 1. (a) def compare_val_w_idx (L): """Compares each value of a list of numbers with its index... L is unaffected by the function call. The function returns a list M of the same length as L. M is 1 when L is bigger than i, M is -1 when L is less than 1, M[1] is 0 when L is equal to 1. www pass Test: L [4,5,6,3,4,5,2,3,4] print (compare_val_w_idx (L)) should print [1, 1, 1, 0, 0, 0, -1, -1, -1]. 1
(L): "Compares each value of a list of numbers with its index... (b) def compare_val_w_idx_no_obj No new objects (except ints) are created during the function call!! None is returned, but L is mutated by the function call. For any list of numbers L, the following code results in True being printed. M compare_val_v_idx (L) compare_val_w_idx_no_obj (L) print (LM) So L is mutated to the return value of compare_val_w_idx (L). HER pass Test: L [4,5,6,3,4,5,2,3,4] compare_val_v_idx_no_obj (L) print (L) should print (1, 1, 1, 0, 0, 0, -1, -1, -1]. "No new objects" means that you should not be creating any new lists. For example, def compare_val_v_idx_no_obj (L): M L.clear() compare_val_v_idx (L) L. extend (M) is NOT an okay solution. (For the pedantic, I'm not counting range (len (L)) as an object even though it is. You're fine to use this.)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- |||||| Created on Sun Mar 27 00:00:00 2022 @author: sarahburnett #%% 1A def compare_val_w_idx (L): """Compares each value of a list of numbers with its index... L is unaffected by the function call. The function returns a list M of the same length as L. M is 1 when L is bigger than i, M is -1 when L is less than i, M is 0 when L[i] is equal to 1. 111111 pass #%% 1B def compare_val_w_idx_no_obj (L): """Compares each value of a list of numbers with its index... No new objects (except ints) are created during the function call!! None is returned, but L is mutated by the function call. For any list of numbers L, the following code results in True being printed. M = compare_val_w_idx (L) compare_val_w_idx_no_obj (L) print (L == M)
M[i] is 1 when L[i] is bigger than i, M[i] is -1 when L[i] is M[ij is o when L[ij is less than i, equal to i. HR pass # % % 1B def compare_val_w_idx_no_obj (L): """Compares each value of a list of numbers with its index... nin No new objects (except ints) are created during the function call!! None is returned, but L is mutated by the function call. For any list of numbers L, the following code results in True being printed. M compare_val_w_idx (L) compare_val_w_idx_no_obj (L) print (L == M) So L is mutated to the return value of compare_val_w_idx(L). |||||| pass