Skip to content

Commit a944928

Browse files
committed
day 20 is updated
1 parent 94e1048 commit a944928

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

Status/Day_20.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
### **Question**
55

6-
>***Please write a program to print the list after removing delete even numbers in [5,6,77,45,22,12,24].***
6+
>***Please write a program to print the list after removing even numbers in [5,6,77,45,22,12,24].***
77
88

99
----------------------
@@ -21,18 +21,27 @@ print li
2121
----------------
2222
**My Solution: Python 3**
2323
```python
24-
#to be written
24+
def isEven(n):
25+
return n%2!=0
2526

27+
li = [5,6,77,45,22,12,24]
28+
lst = list(filter(isEven,li))
29+
print(lst)
30+
```
31+
**OR**
32+
```python
33+
li = [5,6,77,45,22,12,24]
34+
lst = list(filter(lambda n:n%2!=0,li))
35+
print(lst)
2636
```
2737
---------------------
2838

2939

30-
3140
# Question 81
3241

3342
### **Question**
3443

35-
>***By using list comprehension, please write a program to print the list after removing delete numbers which are divisible by 5 and 7 in [12,24,35,70,88,120,155].***
44+
>***By using list comprehension, please write a program to print the list after removing numbers which are divisible by 5 and 7 in [12,24,35,70,88,120,155].***
3645
3746
----------------------
3847
### Hints
@@ -49,8 +58,9 @@ print li
4958
----------------
5059
**My Solution: Python 3**
5160
```python
52-
#to be written
53-
61+
li = [12,24,35,70,88,120,155]
62+
li = [x for x in li if x % 35!=0]
63+
print(li)
5464
```
5565
---------------------
5666

@@ -77,8 +87,9 @@ print li
7787
----------------
7888
**My Solution: Python 3**
7989
```python
80-
#to be written
81-
90+
li = [12,24,35,70,88,120,155]
91+
li = [li[i] for i in range(len(li)) if i%2 != 0]
92+
print(li)
8293
```
8394
---------------------
8495

@@ -87,7 +98,7 @@ print li
8798

8899
### **Question**
89100

90-
>***By using list comprehension, please write a program to print the list after removing the 0th, 2nd, 4th,6th numbers in [12,24,35,70,88,120,155].***
101+
>***By using list comprehension, please write a program to print the list after removing the 2nd - 4th numbers in [12,24,35,70,88,120,155].***
91102
92103
----------------------
93104
### Hints
@@ -100,15 +111,17 @@ Use enumerate() to get (index, value) tuple.***
100111
```python
101112

102113
li = [12,24,35,70,88,120,155]
103-
li = [x for (i,x) in enumerate(li) if i%2!=0]
114+
li = [x for (i,x) in enumerate(li) if i<3 or 4<i]
104115
print li
105116

106117
```
107118
----------------
108119
**My Solution: Python 3**
109120
```python
110121
#to be written
111-
122+
li = [12,24,35,70,88,120,155]
123+
li = [li[i] for i in range(len(li)) if i<3 or 4<i]
124+
print(li)
112125
```
113126
---------------------
114127

@@ -127,18 +140,9 @@ print li
127140
128141
----------------------
129142

130-
**Main author's Solution: Python 2**
143+
**Solution:**
131144
```python
132-
133145
array = [[ [0 for col in range(8)] for col in range(5)] for row in range(3)]
134146
print array
135147
```
136148
----------------
137-
**My Solution: Python 3**
138-
```python
139-
#to be written
140-
141-
```
142-
---------------------
143-
144-

0 commit comments

Comments
 (0)