Python Flashcards

1
Q

value = 42
print(f’{value=}’)

A

value=42

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

*=
+=
-=
/=
%=
**=

A

meghdaro hesab mikona mirize dakhele khode var

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

def func(a, b, /):

A

ghable / hame bayad positional bashan va nemitoona keyword begiran. ba dashtane meghdare default tanaghozi nadare

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

old version of def func(x: int | str):

A

from typing import Union
def func(x: Union[int , str]):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

s = ‘TestString’
remove Test from beginnign

A

s = s.removeprefix(‘Testr’)

s = tavajoh kon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

age aval ya akharessh nadashte bashe chi mishe?
baraye removeprefix va removesuffix

A

hichi, error nemide. kalame khodesh mimune

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

s = ‘TestString’
remove ing from last part of word

A

s = s.removesuffix(‘ing’)
s = tavajoh kon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

class Solution:
def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:
nums1 = [nums2[i - n] if not j else j for i, j in enumerate(nums1)]

what is nums1?

A

nums1 will not changed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how to change list in place inside of a function/method?

A

change elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

nums1[m:]=nums2
nums1[m:]=nums2[:n]

these are changing elements?

A

Yes. both of them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

k%=10 ?
1- k=k%10
2- k = 10% k

A

1- k=k%10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

roman_dyn = {“IV”: 4, “IX”: 9, “XL”: 40, “XC”: 90, “CD”: 400, “CM”: 900}
for i, j in roman_dyn.values():
or
for I, j in roman_dyn.items(): ?

A

for I, j in roman_dyn.items():

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

s = s.replace(i,””)
or s.replace(i,””)

A

s = s.replace(i,””)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

a=” fly me to the moon “

print(a.strip())

A

space ro az 2 taraf pak mikone

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

a=” fly me to the moon “
print(a.split())

A

[‘fly’, ‘me’, ‘to’, ‘the’, ‘moon’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

anagram_map = defaultdict(dict)
anagram_map[1]
print(anagram_map)

A

{1:{}}

17
Q

remove repatitive elemnts out of a list

A

nums=list(dict.fromkeys(nums))
list(set(nums))

18
Q

use hash map for get unique keys of a list

A

nums = [‘a’,’b’,’a’,’b’,’b’,’b’,’b’]
result={}
for i in nums:
result[i]=True

19
Q

all, any

A

hame azaye yek list ro true age bashe mide true baraye all va any ham mesle or amal mikone

20
Q

count

A

tedad ro mishmare. dakhele list va string

21
Q

all any ruye dict

A

rouye keys amal mikone !

22
Q

all any ruye dict values?

A

all(dict.values())