We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Good but you don't really need to print it as a list
Check this:
#!/bin/python3
def countApplesAndOranges(s, t, a, b, apples, oranges):
print (sum(1 for fruit in apples if (fruit + a) >= s and (fruit + a) <= t))
print (sum(1 for fruit in oranges if (fruit + b) >= s and (fruit + b) <= t))
Or simply count of the True and false doing this:
print(sum(s <= a + fruit <= t for fruit in apples))
print(sum(s <= b + fruit <= t for fruit in oranges))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Apple and Orange
You are viewing a single comment's thread. Return to all comments →
Good but you don't really need to print it as a list Check this:
#!/bin/python3
Or simply count of the True and false doing this:
print(sum(s <= a + fruit <= t for fruit in apples)) print(sum(s <= b + fruit <= t for fruit in oranges))