This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
from typing import List | |
import datetime | |
@dataclass | |
class Order: | |
date: datetime.datetime | |
price: float = 0.0 | |
@dataclass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
@dataclass | |
class User: | |
email: str | |
name: str = "First name" | |
surname: str = "Last name" | |
def fullName(self): | |
return self.name + " " + self.surname |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
@dataclass | |
class User: | |
email: str | |
name: str = "First name" | |
surname: str = "Last name" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
@dataclass | |
class User: | |
name: str | |
surname: str | |
email: str | |
user_instance = User('Petros', 'Demetrakopoulos', '[email protected]') | |
print(user_instance) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(monte_carlo(['Ah','Ad'], ['Ac','2d','9s'])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def monte_carlo(hand, table, players=2, samples=10000): | |
dist = [0,0,0] | |
for i in range(samples): | |
outcome = simulate(hand, table, players) | |
dist[outcome] += 1 | |
return list(map(lambda x: x/samples, dist)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def simulate(hand, table, players): | |
hands = [] | |
deck = random.sample(cards,len(cards)) #shuffle the deck | |
hand = hand[:] | |
table = table[:] | |
full = table + hand | |
deck = list(filter(lambda x: x not in full, deck)) | |
#deal cards to players |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from phevaluator import evaluate_cards | |
import random | |
suits = ['d','s','c','h'] | |
ranks = ['A','2','3','4','5','6','7','8','9','T','J','Q','K'] | |
cards = [] | |
for r in ranks: | |
for s in suits: | |
cards.append(r+s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df['coin_toss'] = df['coin_toss'].map({'HEADS': True, 'TAILS': False}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import random | |
age_column = [random.randrange(0,120) for x in range(1000)] | |
df = pd.DataFrame({'age':age_column}) | |
print(df.info(memory_usage="deep")) |