Skip to content

Commit

Permalink
list comprehensin
Browse files Browse the repository at this point in the history
  • Loading branch information
Asabeneh committed Jul 8, 2021
1 parent 99c4d78 commit 306c046
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions 13_Day_List_comprehension/13_list_comprehension.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<sub>Author:
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
<small> First Edition: Nov 22 - Dec 22, 2019</small>
<small> Second Edition: July, 2021</small>
</sub>

</div>
Expand Down Expand Up @@ -93,8 +93,8 @@ positive_even_numbers = [i for i in range(21) if i % 2 == 0 and i > 0]
print(positive_even_numbers) # [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

# Flattening a three dimensional array
three_dimen_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
flattened_list = [ number for row in three_dimen_list for number in row]
list_of_lists = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
flattened_list = [ number for row in list_of_lists for number in row]
print(flattened_list) # [1, 2, 3, 4, 5, 6, 7, 8, 9]
```

Expand All @@ -119,7 +119,7 @@ print(x(arg1, arg2, arg3))
def add_two_nums(a, b):
return a + b

print(2, 3) # 5
print(add_two_nums(2, 3)) # 5
# Lets change the above function to a lambda function
add_two_nums = lambda a, b: a + b
print(add_two_nums(2,3)) # 5
Expand All @@ -134,7 +134,7 @@ print(cube(3)) # 27

# Multiple variables
multiple_variable = lambda a, b, c: a ** 2 - 3 * b + 4 * c
print(multiple_variable(5, 5, 3))
print(multiple_variable(5, 5, 3)) # 22
```

### Lambda Function Inside Another Function
Expand All @@ -151,7 +151,7 @@ two_power_of_five = power(2)(5)
print(two_power_of_five) # 32
```

🌕 Keep up the good work. Keep pushing, the sky is the limit! You have just completed day 13 challenges and you are 13 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
🌕 Keep up the good work. Keep the momentum going, the sky is the limit! You have just completed day 13 challenges and you are 13 steps a head in to your way to greatness. Now do some exercises for your brain and muscles.

## 💻 Exercises: Day 13

Expand Down Expand Up @@ -186,7 +186,7 @@ print(two_power_of_five) # 32
```py
countries = [[('Finland', 'Helsinki')], [('Sweden', 'Stockholm')], [('Norway', 'Oslo')]]
output:
['FINLAND', 'HELSINKI', 'SWEDEN', 'STOCKHOLM', 'NORWAY', 'OSLO']
[['FINLAND','FIN', 'HELSINKI'], ['SWEDEN', 'SWE', 'STOCKHOLM'], ['NORWAY', 'NOR', 'OSLO']]
```
5. Change the following list to a list of dictionaries:
```py
Expand All @@ -198,7 +198,7 @@ print(two_power_of_five) # 32
```
6. Change the following list of lists to a list of concatenated strings:
```py
names = [[('Asabeneh', 'Yetaeyeh')], [('David', 'Smith')], [('Donald', 'Trump')], [('Bill', 'Gates')]]
names = [[('Asabeneh', 'Yetayeh')], [('David', 'Smith')], [('Donald', 'Trump')], [('Bill', 'Gates')]]
output
['Asabeneh Yetaeyeh', 'David Smith', 'Donald Trump', 'Bill Gates']
```
Expand Down

0 comments on commit 306c046

Please sign in to comment.