Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions about_lists.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Task 1. Create a list containing squares for number from 1 up to 10.
# Use list comprehension
nums = [x**2 for x in range(1, 11)]

# Task 2. Create a list containig numbers leap years in the future from 2000 up to 2100
# Task 2. Create a list containing numbers leap years in the future from 2000 up to 2100
# Use list comprehension with if condition
# Hint: leap year is a year divisible by 4, but not by 100, unless it is divisible by 400

def is_leap(year):
return True
leap_year = [year for year in range(2000, 2101) if (year % 4 == 0 and year % 100) or year % 400 == 0]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done!



# Task 3. You are given a dictionary with vehicles and their weights:
vehicles = {'sedan': 1550, 'Pickup': 2000, 'bicycle': 20, 'TRUCK': 7000, 'motorcycle': 200, 'Minivan': 1700, 'SUV': 2500, 'van': 3500, 'Semi': 12000, 'Bus': 3000}

# With single list comprehension select vehicle those weight is below 5000 kg
# Convert names to upper-case within same list comprehension
# Convert names to upper-case within same list comprehension
selected_vehicles = [vehicle.upper() for vehicle, weight in vehicles.items() if weight < 5000]
print(selected_vehicles)