From 4406d6c52363a72a03dfb14e4bb6b3da5dec7327 Mon Sep 17 00:00:00 2001 From: plinphon Date: Tue, 19 Sep 2023 15:07:00 +0700 Subject: [PATCH 1/4] dccdc --- about_lists.py | 1 + 1 file changed, 1 insertion(+) diff --git a/about_lists.py b/about_lists.py index 58b8331..927fbf9 100644 --- a/about_lists.py +++ b/about_lists.py @@ -6,6 +6,7 @@ # Hint: leap year is a year divisible by 4, but not by 100, unless it is divisible by 400 def is_leap(year): + x="dd" return True From d47fcfb352d31ec99928fc345da4d3e32700b2f2 Mon Sep 17 00:00:00 2001 From: plinphon Date: Tue, 19 Sep 2023 15:49:42 +0700 Subject: [PATCH 2/4] fefe --- about_lists.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/about_lists.py b/about_lists.py index 927fbf9..b6b7126 100644 --- a/about_lists.py +++ b/about_lists.py @@ -1,17 +1,43 @@ # Task 1. Create a list containing squares for number from 1 up to 10. # Use list comprehension +lis=[] +for i in range(10): + num=i+1 + num=num**2 + lis.append(num) +print(lis) # Task 2. Create a list containig 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): - x="dd" - return True + if year%4 == 0: + if year%400 == 0: + return True + elif year%100 == 0: + return False + else: + return True + else: + return False + +leap_years=[] +for i in range(2000,2101): + if is_leap(i): + leap_years.append(i) +print(leap_years) # 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 \ No newline at end of file + +lis2 = list(vehicles.items()) + +for i in range(len(lis2)): + if lis2[i][1]< 5000: + vehicles[lis2[i][0].upper()] = lis2[i][1] + vehicles.pop(lis2[i][0]) +print(vehicles) \ No newline at end of file From 073b4963668ddfc05bf63066073eefd905d0d927 Mon Sep 17 00:00:00 2001 From: plinphon Date: Tue, 19 Sep 2023 19:35:31 +0700 Subject: [PATCH 3/4] ede --- about_lists.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/about_lists.py b/about_lists.py index b6b7126..5f6811c 100644 --- a/about_lists.py +++ b/about_lists.py @@ -1,10 +1,7 @@ # Task 1. Create a list containing squares for number from 1 up to 10. # Use list comprehension -lis=[] -for i in range(10): - num=i+1 - num=num**2 - lis.append(num) +lis=[(i+1)**2 for i in range(10)] + print(lis) # Task 2. Create a list containig numbers leap years in the future from 2000 up to 2100 @@ -22,10 +19,8 @@ def is_leap(year): else: return False -leap_years=[] -for i in range(2000,2101): - if is_leap(i): - leap_years.append(i) +leap_years=[i for i in range(2000,2101) if is_leap(i)] + print(leap_years) @@ -34,10 +29,5 @@ def is_leap(year): # With single list comprehension select vehicle those weight is below 5000 kg -lis2 = list(vehicles.items()) - -for i in range(len(lis2)): - if lis2[i][1]< 5000: - vehicles[lis2[i][0].upper()] = lis2[i][1] - vehicles.pop(lis2[i][0]) -print(vehicles) \ No newline at end of file +lis2 = [i.upper() for i,j in vehicles.items() if j <5000] +print(lis2) \ No newline at end of file From 2c54cb0f5a6ed8ea08ff0c1e77362c7c56451cb6 Mon Sep 17 00:00:00 2001 From: plinphon Date: Tue, 19 Sep 2023 19:43:25 +0700 Subject: [PATCH 4/4] finish --- about_lists.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/about_lists.py b/about_lists.py index 5f6811c..33b1302 100644 --- a/about_lists.py +++ b/about_lists.py @@ -27,7 +27,7 @@ def is_leap(year): # 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 +# Withff single list comprehension select vehicle those weight is below 5000 kg -lis2 = [i.upper() for i,j in vehicles.items() if j <5000] -print(lis2) \ No newline at end of file +liss = [i.upper() for i,j in vehicles.items() if j <5000] +print(liss) \ No newline at end of file