You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Status/Day_20.md
+25-21Lines changed: 25 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
4
4
### **Question**
5
5
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].***
7
7
8
8
9
9
----------------------
@@ -21,18 +21,27 @@ print li
21
21
----------------
22
22
**My Solution: Python 3**
23
23
```python
24
-
#to be written
24
+
defisEven(n):
25
+
return n%2!=0
25
26
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(lambdan:n%2!=0,li))
35
+
print(lst)
26
36
```
27
37
---------------------
28
38
29
39
30
-
31
40
# Question 81
32
41
33
42
### **Question**
34
43
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].***
36
45
37
46
----------------------
38
47
### Hints
@@ -49,8 +58,9 @@ print li
49
58
----------------
50
59
**My Solution: Python 3**
51
60
```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)
54
64
```
55
65
---------------------
56
66
@@ -77,8 +87,9 @@ print li
77
87
----------------
78
88
**My Solution: Python 3**
79
89
```python
80
-
#to be written
81
-
90
+
li = [12,24,35,70,88,120,155]
91
+
li = [li[i] for i inrange(len(li)) if i%2!=0]
92
+
print(li)
82
93
```
83
94
---------------------
84
95
@@ -87,7 +98,7 @@ print li
87
98
88
99
### **Question**
89
100
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].***
91
102
92
103
----------------------
93
104
### Hints
@@ -100,15 +111,17 @@ Use enumerate() to get (index, value) tuple.***
100
111
```python
101
112
102
113
li = [12,24,35,70,88,120,155]
103
-
li = [x for (i,x) inenumerate(li) if i%2!=0]
114
+
li = [x for (i,x) inenumerate(li) if i<3or4<i]
104
115
print li
105
116
106
117
```
107
118
----------------
108
119
**My Solution: Python 3**
109
120
```python
110
121
#to be written
111
-
122
+
li = [12,24,35,70,88,120,155]
123
+
li = [li[i] for i inrange(len(li)) if i<3or4<i]
124
+
print(li)
112
125
```
113
126
---------------------
114
127
@@ -127,18 +140,9 @@ print li
127
140
128
141
----------------------
129
142
130
-
**Main author's Solution: Python 2**
143
+
**Solution:**
131
144
```python
132
-
133
145
array = [[ [0for col inrange(8)] for col inrange(5)] for row inrange(3)]
0 commit comments