Problems
Contest
Discuss
Interview
Online Interview
Assessment
Store
Redeem
Premium
For you
For you
Create
Most Votes
All Time
Newest
No search result
Create
Amazon | Tech Screen| SDE 1
kd588
209
Interview
Python
Your previous Python 3 content is preserved below:
# Step 1
# Write a function that takes a list of rows and a column name
# It should return the summed price for each unique value of column name
rows = [
{'country': 'US', 'page': 'SUBCATEGORY', 'site': 'IOS', 'price': 0.25},
{'country': 'US', 'page': 'SUBCATEGORY', 'site': 'IOS', 'price': 0.25},
{'country': 'US', 'page': 'SUBCATEGORY', 'site': 'IOS', 'price': 0.25},
{'country': 'US', 'page': 'SUBCATEGORY', 'site': 'IOS', 'price': 0.25},
{'country': 'US', 'page': 'CATEGORY', 'site': 'IOS', 'price': 0.25},
{'country': 'US', 'page': 'CATEGORY', 'site': 'IOS', 'price': 0.25},
{'country': 'US', 'page': 'CATEGORY', 'site': 'IOS', 'price': 0.25},
{'country': 'US', 'page': 'CATEGORY', 'site': 'IOS', 'price': 0.25},
{'country': 'US', 'page': 'CATEGORY', 'site': 'WEB', 'price': 0.25},
{'country': 'US', 'page': 'CATEGORY', 'site': 'WEB', 'price': 0.25},
{'country': 'CA', 'page': 'CATEGORY', 'site': 'WEB', 'price': 0.25},
{'country': 'CA', 'page': 'CATEGORY', 'site': 'WEB', 'price': 0.25},
]
def groupBy(rows, column):
print(groupBy(rows,'country'))
'''expected = [
['US', 2.5],
['CA', 0.5]
]
assert groupBy(rows, 'country') == expected
expected = [
['SUBCATEGORY', 1.0],
['CATEGORY', 2.0]
]
assert groupBy(rows, 'page') == expected
'''
# Step 2
# Write a function that takes a list of rows and a list of column names
# It should return the summed price for each unique combination of column names
'''
def groupByMultiple(rows, columns):
pass
expected = [
['US', 'SUBCATEGORY', 1.0],
['US', 'CATEGORY', 1.5],
['CA', 'CATEGORY', 0.5],
]
assert groupByMultiple(rows, ['country', 'page']) == expected
'''
0
1
Comments (1)
Sort by:
Best
Comment
1
Explore
Download App
Support
Terms
Privacy Policy
More
Copyright © 2026 LeetCode
United States