Created
June 17, 2020 03:42
-
-
Save jaidevd/b1eda0170dada0d55d034c68f02146f2 to your computer and use it in GitHub Desktop.
Solutions for exercises in Python bootcamp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List comprehension | |
x = [i for i in range(1, 21)] | |
y = [i ** 2 for i in x] | |
y = [i ** 2 for i in range(1, 21)] | |
# Median of a list of numbers | |
def median(x): | |
x.sort() | |
L = len(x) | |
if L % 2 == 0: | |
left = x[:(L/2)] | |
right = x[(L/2):] | |
med = (left + right) / 2 | |
else: | |
med = x[(L - 1) / 2 + 1] | |
return med | |
data = [{'name': "BYJU's", 'industry': 'e-tech', 'funding (USD)': 200000000}, | |
{'name': 'Flipkart', 'industry': 'e-commerce', 'funding (USD)': 2500000000}, | |
{'name': 'Shuttl', 'industry': 'transport', 'funding (USD)': 8048394}] | |
# Adding a column for location: | |
data[0]['location'] = 'Mumbai' | |
data[1]['location'] = 'Bangalore' | |
data[2]['location'] = 'Chennai' | |
# Adding a record for a new startup | |
data.append({{'name': 'PayTM', 'industry': 'fintech', 'funding (USD)': 42_000_000, 'location': 'Delhi'}}) | |
# Maximum funding for a startup in a non-metro city | |
funding_non_metro = [] | |
for record in data: | |
if record['city'] not in METROS: | |
funding_non_metro.append(record['funding']) | |
print(max(funding_non_metro)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment