List methods
Let's practice list methods!
Let's imagine a situation: you went to the market and filled your baskets (basket1
and basket2
) with fruits. You wanted to have one of each kind but realized that some fruits were put in both baskets.
Task 1. Your first task is to remove everything from basket2
that is already present in basket1
.
Task 2. After the removal it is reasonable to anticipate that one of the baskets might weigh more compared to the another (all fruit kinds weight the same). Therefore, the second task is to transfer some fruits from a heavier basket to the lighter one to get approximately the same weight/amount of fruits.
Este exercício faz parte do curso
Practicing Coding Interview Questions in Python
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Remove fruits from basket2 that are present in basket1
for item in basket1:
if ____:
basket2.____
print('Basket 1: ' + str(basket1))
print('Basket 2: ' + str(basket2))