Skip to content

Commit ea80a81

Browse files
Lists, Dictionaries sorting for lists, sort by key in dict, sort by value in dict, updating values and more
1 parent d68c88c commit ea80a81

File tree

4 files changed

+137
-89
lines changed

4 files changed

+137
-89
lines changed

Flask/Basic.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Basic Flask App
2+
3+
4+
from flask import Flask
5+
6+
app = Flask(__name__)
7+
8+
# I use the app.route decorator telling Flask this is the home page
9+
@app.route("/")
10+
def homePage():
11+
return "This is the home page y'all"
12+
13+
if(__name__=="__main__"):
14+
app.run(debug=True)
15+

Flask/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Flask
2+
3+
- Framework that provides me with libraries to build lightweight web apps
4+
5+
#### Installation using pip
6+
7+
```python
8+
pip install flask
9+
```
10+
11+
#### Run Method in flask has 4 parameters
12+
13+
1. host: specify the host you want to run your Flask app on (default: 127.0.0.1 i.e. Localhost)
14+
15+
2. port: specify the port number where you wish to run your Flask app on (default: 5000)
16+
17+
3. debug: boolean value telling Flask whether you want debugging information to be provided to you(default: false)
18+
19+
4. options: information which you want to be forwarded to the server
20+
21+
22+
#### Routing In Flask
23+
24+
```python
25+
from flask import Flask
26+
app = Flask(__name__)
27+
28+
@app.route("/home")
29+
def home():
30+
return("This is the home page on my WS")
31+
32+
@app.route("/about")
33+
def about():
34+
return("This is the about page on my WS")
35+
36+
@app.route("/services")
37+
def services():
38+
return("This is the services page on my WS")
39+
40+
@app.route("/contact")
41+
def about():
42+
return("This is the contact us page on my WS")
43+
44+
45+
if(__name__=="__main__"):
46+
app.run(debug=True)
47+
```

Lists&Dictionaries/ListDictTups.py

Lines changed: 0 additions & 87 deletions
This file was deleted.

Lists&Dictionaries/README.md

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
### Lists & Dictionaries
1+
## Lists & Dictionaries
22

33

4-
#### List Methods Table
4+
- Can store different data types in a list
5+
6+
### How to declare a list
7+
8+
```python
9+
listName=[2,5,3,5,3,5]
10+
listName2=[2, "Nelan", "Olivia", "Mariana", "Angela","Nelan", "Alan5683706342", "0forSpace"]
11+
print(listName2)
12+
```
13+
14+
#### List Methods
515

616
| |Start | Method |Output |
717
|----------------|-----------------|------------|---------------|
@@ -18,3 +28,66 @@
1828
|size(i.e. says how big your list/array is) | △▢☆ |print(len("△","▢","☆")) |3 |
1929
|sort | [ "z", "e", "l" ] |.sort() |[ "e", "l", "z" ] |
2030

31+
### Slice my original list and place the new list in the old list's memory location aka override var
32+
33+
```python
34+
myNewList=myNewList[0:6]
35+
myNewList.append("ALAN <3 C!!!!")
36+
```
37+
38+
## Tuples
39+
40+
- A tuple is a collection which is:
41+
- ordered
42+
- unchangeable(no modification, no adding, no removing).
43+
- In Python tuples are written with parenthesis
44+
45+
```python
46+
omarTuple=(5,2,3,5,41,4)
47+
print(omarTuple)
48+
print("The number location of 'For Angela: ' is: %d" %omarTuple.index("For Angela: "))
49+
```
50+
51+
## Dictionaries
52+
53+
### Declaration of a Dictionary
54+
55+
```python
56+
goodMajors={"Alan":"CS", "Waleed":"CS", "Scott": "CS", "Nouhaila":"CSE", "Younes":"CS", "Zakaria":"PE"}
57+
print(goodMajors)
58+
```
59+
60+
### Check if a key exists in a given dictionary by invoking in method:
61+
62+
```python
63+
print("Alan" in goodMajors)
64+
```
65+
66+
#### Delete a key and return to us the associated value
67+
68+
```python
69+
print(goodMajors.pop("Zakaria"))
70+
```
71+
72+
### Print the keys of a dictionary
73+
74+
```python
75+
print(goodMajors.keys())
76+
```
77+
78+
### Sort a dictionary by key
79+
80+
```python
81+
goodMajors={"Alan":"CS", "Waleed":"CS", "Scott": "CS", "Nouhaila":"CSE", "Younes":"CS", "Zakaria":"PE"}
82+
sortedNames=sorted(goodMajors.items(),key=lambda v:v[0])
83+
84+
for x in sortedNames:
85+
print(x[0],x[1])
86+
```
87+
88+
89+
### Update a value within a dictionary
90+
91+
```python
92+
goodMajors["Alan"]= "2526 56837 7652626"
93+
```

0 commit comments

Comments
 (0)