Skip to content

Commit 9f8dfe2

Browse files
author
Orchardson
authored
Merge pull request #1 from moringaschool/master
pull
2 parents e8c5c0d + 17cc60b commit 9f8dfe2

13 files changed

Lines changed: 353 additions & 52 deletions

.idea/workspace.xml

Lines changed: 112 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

paren_matcher/paren_matcher.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,3 @@
88
#
99
#
1010

11-
12-
def parchecker(symbolString):
13-
s = Stack()
14-
balanced = True
15-
index = 0
16-
while index < len(symbolString) and balanced:
17-
symbol = symbolString[index]
18-
if symbol == "(":
19-
s.push(symbol)
20-
else:
21-
if s.isEmpty():
22-
balanced = False
23-
else:
24-
s.pop()
25-
26-
index = index + 1
27-
28-
if balanced and s.isEmpty():
29-
return True
30-
else:
31-
return False
32-
33-
print(parChecker('((()))'))
34-
print(parChecker('(()'))

paren_matcher/stack.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Stack:
2+
def __init__(self):
3+
self.items = []
4+
5+
def isEmpty(self):
6+
return self.items == []
7+
8+
def push(self, item):
9+
self.items.append(item)
10+
11+
def pop(self):
12+
return self.items.pop()
13+
14+
def peek(self):
15+
return self.items[len(self.items)-1]
16+
17+
def size(self):
18+
return len(self.items)

readme.md

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,92 @@ presses('LOL') # 9
126126
presses('How R u 2day') # 23
127127

128128
Bonus: Try to avoid hard-coding the number of button presses for each letter!
129-
Resource:
130-
Use python [Dictionaries](http://www.learnpython.org/en/Dictionaries) in this exercise
129+
130+
Resource:Use python [Dictionaries](http://www.learnpython.org/en/Dictionaries) in this exercise
131+
132+
133+
### Question 6
134+
##### List Comprehension
135+
136+
Let’s say I give you a list saved in a variable: a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100].
137+
Write one line of Python that takes this list a and makes a new list that has only the even elements of this list in it.
138+
139+
The idea of a list comprehension is to make code more compact to accomplish tasks involving lists.
140+
Take for example this code:
141+
142+
```python
143+
144+
years_of_birth = [1990, 1991, 1990, 1990, 1992, 1991]
145+
ages = []
146+
for year in years_of_birth:
147+
ages.append(2014 - year)
148+
```
149+
150+
And at the end, the variable ages has the list [24, 23, 24, 24, 22, 23].
151+
What this code did was translate the years of birth into ages, and it took us a for loop and an append statement to a new list to do that.
152+
153+
Compare to this piece of code:
154+
155+
```python
156+
157+
years_of_birth = [1990, 1991, 1990, 1990, 1992, 1991]
158+
ages = [2014 - year for year in years_of_birth]
159+
160+
```
161+
162+
The second line here - the line with ages is a list comprehension.
163+
164+
It accomplishes the same thing as the first code sample - at the end,
165+
the ages variable has a list containing [24, 23, 24, 24, 22, 23],
166+
the ages corresponding to all the birthdates.
167+
168+
The idea of the list comprehension is to condense the for loop and the list appending into one simple line. Notice that the for loop just shifted to the end of the list comprehension, and the part before the for keyword is the thing to append to the end of the new list.
169+
170+
Happy coding! :)
171+
172+
173+
### Question 6
174+
#### List Overlap
175+
176+
Take two lists, say for example these two:
177+
```python
178+
179+
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
180+
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
181+
182+
```
183+
184+
And write a program that returns a list that contains only the elements that are common between the lists (without duplicates).
185+
Make sure your program works on two lists of different sizes.
186+
187+
Bonus:
188+
189+
Randomly generate two lists to test this
190+
Write this in one line of Python
191+
192+
List properties (In other words, “things you can do with lists.”)
193+
194+
One of the interesting things you can do with lists in Python is figure out whether something is inside the list or not. For example:
195+
196+
```python
197+
198+
>>> a = [5, 10, 15, 20]
199+
>>> 10 in a
200+
True
201+
>>> 3 in a
202+
False
203+
204+
```
205+
206+
You can of course use this in loops, conditionals, and any other programming constructs.
207+
208+
```python
209+
210+
list_of_students = ["Michele", "Sara", "Cassie"]
211+
212+
name = input("Type name to check: ")
213+
if name in list_of_students:
214+
print("This student is enrolled.")
215+
216+
```
217+
Happy coding! :)

solutions/question_five.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
###Loading

solutions/question_five.py~

Whitespace-only changes.

solutions/question_four.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import random
2+
3+
class PassGenerator:
4+
def __init__(self):
5+
pass
6+
7+
8+
def genpass(self):
9+
alphabet = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
10+
pw_length = 8
11+
mypw = ""
12+
13+
for i in range(pw_length):
14+
next_index = random.randrange(len(alphabet))
15+
mypw = mypw + alphabet[next_index]
16+
17+
print(mypw)
18+
19+
20+
21+
def main():
22+
23+
password = int(raw_input("How strong should you password be"))
24+
25+
#b = ["sosmall", "weakpass", "hmm..so weak"]
26+
if password <= 5:
27+
a = random.randint(1, 3)
28+
b = ["sosmall", "weakpass", "hmm..so weak", "toosmall"]
29+
print('Weak password.')
30+
print(random.choice(b))
31+
elif password >6:
32+
print('strong password.')
33+
dog = PassGenerator()
34+
dog.genpass()
35+
36+
37+
if __name__ == '__main__':
38+
main()

0 commit comments

Comments
 (0)