0% found this document useful (0 votes)
10 views4 pages

Intro To Python Cheat Sheet 2

Tel aviv university, version 2

Uploaded by

ariellerbrill
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

Intro To Python Cheat Sheet 2

Tel aviv university, version 2

Uploaded by

ariellerbrill
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

dictionary j

phonebook
example

CONDITIONAL STATEMENTS: ONE LINE IF-ELSE:


n = 18
if n%2 == 0:
b=0
else:
b=1
*
b = 0 if n%2 = = 0 else 1

recursion
examples

WHILE LOOPS:
>
-

for ________
iterator name
in _________
iterable object STEPS TO SOLVE: MOED B 2024
7 kindersen ke ikaid do used STEP 1: WRITE INPUTS AND OUTPUTS AND VARIABLE TYPES
name , type (body)
,

inputs : mandates list (1st) -


>
- <party-name : X Mandates))
rivalries . 1st Cist) -[(party , party 2)
Sparty [p P2733
-:Stes:x
output : dict :
"riv ,
:
..

key val

STEP 2: WRITE STEPS OF WHAT I WANT AND


NEED TO DO IN call
OUTLI NE OF CODE
"result"
* 1. create new rival

party-dict
list =
[]

1) new empty dist


2 .
new dist >
-

,
.
3 loop over rival tuples [P PL]
..

tuple 2 cases :
a check if party is in :

2) loop over tuples in mandate list b. add cases to party tuples Pi = in


. add
3 info to dist
a) name element 1
P2Rad
-

b) party size element 2 -


P-e add

& "mandates" "rivals" : ["Di ,p="]3


I> out put
* = : x
,

add pair to result- key : name ,


val-partydict
STEP 3: CODE result = 53
for name ,
mandates in mandates list -

rivals = [J
for P P2 in rivalries list :
,
-

if p,
= =
name :

Mu rivals append(P2]
elif Dz
== name :

rivals .
append [P ) ,

party-infol"mandates") =
mandates
party-info["rivals"] = rivals

result [name] info


=
party -

return result

RECURSION: 1) base case: n=0, 0 n=1,1 no formula needed to find 3)fibo(n):


recursive step:
2)recursive statement: not in code. For any prob a little if n=0: op1 = fibo (n-1)
-base case -> smaller simpler or closer to base case I have return 0 op2 = fibo (n-2)
return op1 + op2
instances -> original problem if n=1:
return 1
2

TEST EXAMPLES
PARTS 1-2

-
OOP SOLUTION: MOED A 2025 take a
deep
breath. &

def--repr--(Self] :
big-name = self name upper (
.
numpy
-1
MOED A 2025:
shade : self shade

S kg-weight
result-Str :
=

big
self

.
.

name
weight/1000
+ " + str(shade) + -" str

&
>
- output : SOCK : 200 0
,
.

05kg

ternary segmentation histogram histogram + cum_sum

modify class Item to calculate total weight


.

considering own
weight + nested items
weight :
&
> [1 52 4
, , 3]
input: histogram
,

output: list of cumulative sums

a
Creating and Binary Segmentation 3
Reading Noise

Noise No Overflow

: 2024 /Rand :NEI

Transpose M
Masking 2

Squeeze

Dark Noise No Overflow

Darken Threshold

MATRIX SLICING ↓
1) 1319x13148

image gradient:
itis step
fits IM :

Morph by Neighborhood
upshifted Im :

Erosion and Dilation Erosion Example:


brightening image:
‫יהיה‬ Y
!! ‫בסדר‬

GOAL 1: Create a df (df_partial) that contains


the first, third, and fifth lines in df
option 1:
x=[1,3,5]
df_partial = df. iloc[x]
option 2: df_partial = df.iloc[[1,3,5]]
option 3: df_partial=df.iloc[1:7:2]
display(df_partial)
GOAL 2: fetch the last line from df_partial

a
sorts values in a defined column
the rest of the columns do not move
but the order of them will change MOED A 2025: PANDAS d d7
-
Dilin

Takes a dataframe, returns new column.


Value in each new column is: (corresponding price
val x corresponding availability val) / average of
all availability values*
*including NaN values as 0 734 ble'M

file-dataframe Index starting from 10*

connect 3 dataframes

>
- this
style of

question style of answer


L BREAKDOWN:
Understand the Inputs:

-Image represented as numpy array, each pixel = int value


-Function takes kernel size k (tuple) that defines size of
regions
-Pooling = Reduce image size while preserving important info
MOED A 2025: Processing the Image:
Numpy -The function has a k×k window or kernel, that moves over
the input image.
-For each window, compute max - min values
-The resulting values form the new downsampled (pooled)
-
image.

You might also like