Skip to content

Commit fb608b1

Browse files
committed
day 21 is updated
1 parent a944928 commit fb608b1

File tree

1 file changed

+40
-20
lines changed

1 file changed

+40
-20
lines changed

Status/Day_21.md

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88

99
----------------------
1010
### Hints
11-
> ***Use list comprehension to delete a bunch of element from a list.
12-
Use enumerate() to get (index, value) tuple.***
11+
> ***Use list comprehension to delete a bunch of element from a list.Use enumerate() to get (index, value) tuple.***
1312
1413
----------------------
1514

@@ -22,13 +21,13 @@ print li
2221
----------------
2322
**My Solution: Python 3**
2423
```python
25-
#to be written
26-
24+
li = [12,24,35,70,88,120,155]
25+
li = [li[i] for i in range(len(li)) if i not in (0,4,5)]
26+
print(li)
2727
```
2828
---------------------
2929

3030

31-
3231
# Question 86
3332

3433
### **Question**
@@ -50,8 +49,9 @@ print li
5049
----------------
5150
**My Solution: Python 3**
5251
```python
53-
#to be written
54-
52+
li = [12,24,35,24,88,120,155]
53+
li.remove(24) # this will remove only the first occurrence of 24
54+
print(li)
5555
```
5656
---------------------
5757

@@ -79,8 +79,21 @@ print li
7979
----------------
8080
**My Solution: Python 3**
8181
```python
82-
#to be written
83-
82+
list1 = [1,3,6,78,35,55]
83+
list2 = [12,24,35,24,88,120,155]
84+
set1= set(list1)
85+
set2= set(list2)
86+
intersection = set1 & set2
87+
print(intersection)
88+
```
89+
**OR**
90+
```python
91+
list1 = [1,3,6,78,35,55]
92+
list2 = [12,24,35,24,88,120,155]
93+
set1= set(list1)
94+
set2= set(list2)
95+
intersection = set.intersection(set1,set2)
96+
print(intersection)
8497
```
8598
---------------------
8699

@@ -116,13 +129,28 @@ print removeDuplicate(li)
116129
----------------
117130
**My Solution: Python 3**
118131
```python
119-
#to be written
132+
li = [12,24,35,24,88,120,155,88,120,155]
133+
for i in li:
134+
if li.count(i) > 1:
135+
li.remove(i)
136+
print(li)
137+
```
138+
**OR**
139+
```python
140+
def removeDuplicate( li ):
141+
seen = {} # dictionary
142+
for item in li:
143+
if item not in seen:
144+
seen[item] = True
145+
yield item
120146

147+
li = [12, 24, 35, 24, 88, 120, 155, 88, 120, 155]
148+
ans = list(removeDuplicate(li))
149+
print(ans)
121150
```
122151
---------------------
123152

124153

125-
126154
# Question 89
127155

128156
### **Question**
@@ -136,7 +164,7 @@ print removeDuplicate(li)
136164
137165
----------------------
138166

139-
**Main author's Solution: Python 2**
167+
**Solution:**
140168
```python
141169
class Person(object):
142170
def getGender( self ):
@@ -156,11 +184,3 @@ print aMale.getGender()
156184
print aFemale.getGender()
157185
```
158186
----------------
159-
**My Solution: Python 3**
160-
```python
161-
#to be written
162-
163-
```
164-
---------------------
165-
166-

0 commit comments

Comments
 (0)