0% found this document useful (0 votes)
7 views2 pages

Python Code

The code to help you to remind of Python features

Uploaded by

Dmitry Vorobiov
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)
7 views2 pages

Python Code

The code to help you to remind of Python features

Uploaded by

Dmitry Vorobiov
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/ 2

from random import randint

def run():
gen = gen_dict(10)
values = list(gen.values())
values = sorted(values, key=lambda n: n)
print(values)
gen_fixed = {k: v*100 for k, v in gen.items()}
print(gen_fixed)
l = []
l.append(1)
l.extend([2, 3])

from collections import defaultdict


a = defaultdict(lambda: 0)
a.update({'one': 1, 'three': 3, 'two': 2})
l = list(a.values())
l.sort(key=lambda a: -a)
print(l)
a["value"]
a.get("")
tup = [(1, "hello"), (2, "world")]
sorted(tup, key=lambda student: student[0], reverse=True)

for idx, x in enumerate(l):


print(idx, x)

n = 2
if n != 4:
print("")
if n != 4:
print("e")

d = {}
d2 = {'miu': 4, 'leo': 34, 'aad': 45}

for i, v in d2.items():
print(v)
d['dd'] = 1

from dataclasses import dataclass


@dataclass
class Item:
name: str
price: float
quantity: int

def cost(self) -> float:


return self.price * self.quantity

def gen_dict(records_num):
return {i: randint(0, 1000) for i in range(records_num)

class Car:
def __init__(self, speed):
self.speed = speed

def distance(self, time):


return self.speed * time

class SuperCar(Car):
def __init__(self, speed, accel):
self.speed = speed
self.accel = accel

def distance(self, time):


return super().distance(time) * self.accel

def distance2(self, time):


return Car.distance(self,time) * self.accel
if __name__ == "__main__":
run()
from collections import namedtuple
Point = namedtuple("Point", "x y")

You might also like