---
# System prepended metadata

title: myPythonNotebook

---

# myPythonNotebook
[good online book for beginners](https://greenteapress.com/wp/think-python-2e/)

# Learning steps
setup
- python, vscode, git, pip

basic cmd use
- python -v
- vscode

python core concepts
- output
- data types
- input
- type casting
    - int(input())
- operators
- if else
- loop
- list, string
- while loop
- for loop
- module, import
- math module
- // next level
- mutable, immutable
- set, dict, tuple
- function
- recursion

syntax
- indentation
- keep spaces between comma

problems to do
https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/1


# array
create 2D array
```python 
rn, cn = (3, 5)
arr = [[0 for _ in range(cn)] for _ in range(rn)]
arr2 = [[0] * cn] * rn
arr3 = []
for _ in range(rn):
    temp = []
    for _ in range(cn):
        temp.append(0)
    arr3.append(temp)
```
# tuple
You cannot remove elements from the tuple
https://www.w3schools.com/python/python_tuples_unpack.asp

# set
list cant be an elem of set, but tuple can
```python!
#create an empty set
set1 = set()
bandNameSet = {"The Cabs", "3nd"}
set1.add(int(input()))
x = int(input())
#2 ways to remove elements, only use .remove(x) when x is definitely in the set, otherwise use .discard(x)
if x in set1:
    set1.remove(x)
set1.discard(x)
#joining other sets to set3
set3.update(set1, set2)
#iterate through the set
for idx, x in enumerate(set):
    print("index ": idx + ", set_value: " + x)
```

list and set are interchangable by list(mySet) or set(myList)

# dictionary
```python=
studentIdList = {
    "Peter":3012345670, 
    "Jaylen":3022345670}
#search if x is one of the key in the dict
if x in myList: print("yes")
#get value
myDict.get(key)
#get key
#O(n) iterate the container
#add new key-value pair
myDict.update({key:value})
#remove a key-value pair
del myDict[key]
#loop through key
for x in myMap: ...
#loop through key, value
for thisKey, thisValue in myMap: ...

```
# string
## fstring
```python=
a = int(input())
b = int(input())
c = a**b
print(f'{a} ** {b} is {c}')
```
## rstring
ignore special character (i.e. \n \r \a)

# string functions
## s.find()
## s.replace()

# map(function, para1, para2, ...)
create an object with outputs from the function with the given parameters

# filter
only 1 parameter (a list)
create an object with inputs verfied by the function
```python=
#dont output this
filter(func1, para)
#have to make it into a list first
list(filter(func1, para))
```
# lambda function
lambda para1, para2, ... : (content)

