181 lines
3.2 KiB
Python
181 lines
3.2 KiB
Python
from typing import List, Set, Dict, Tuple
|
|
|
|
# a: int = 2
|
|
# b: float = 2.3
|
|
# c: str = "lkasldkjaslkjdasd"
|
|
# cc: bytes = b"AAA"
|
|
# d: None = None
|
|
# e: bool = True
|
|
# f: bool = False
|
|
# k: Tuple[int, str, str] = (1, "hello", "world")
|
|
|
|
# g: List[int] = [7]
|
|
# j: Set[str] = {"friend a", "friend b"}
|
|
# i: Dict[str, int] = {"4": 6, "6": 8}
|
|
|
|
# import collections
|
|
|
|
# print(dir(collections))
|
|
|
|
# i["5"] = 7
|
|
# print(dict[str])
|
|
|
|
#
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class Card:
|
|
suit: str
|
|
rank: int # 1 -> ace, 10+ -> jack, queen, king
|
|
|
|
def __str__(self) -> str:
|
|
if self.rank == 1:
|
|
rank_str = "ace"
|
|
elif self.rank == 10:
|
|
rank_str = "jack"
|
|
elif self.rank == 11:
|
|
rank_str = "queen"
|
|
elif self.rank == 12:
|
|
rank_str = "king"
|
|
else:
|
|
rank_str = str(self.rank)
|
|
return f"{rank_str} of {self.suit}"
|
|
|
|
# def __lt__(self, other) -> bool:
|
|
# if self.suit != other.suit:
|
|
# return self.suit < other.suit
|
|
# else:
|
|
# return self.rank < other.rank
|
|
|
|
|
|
hand: List[Card] = [
|
|
Card(suit="clubs", rank=6),
|
|
Card(suit="clubs", rank=5),
|
|
Card(suit="spades", rank=1),
|
|
Card(suit="hearts", rank=10),
|
|
]
|
|
|
|
|
|
def suit_first(card: Card) -> Tuple:
|
|
return (card.suit, card.rank)
|
|
|
|
|
|
def rank_first(card: Card) -> Tuple:
|
|
return (card.rank, card.suit)
|
|
|
|
|
|
# hand.sort(key=suit_first)
|
|
# hand.sort(key=rank_first)
|
|
# print(hand)
|
|
|
|
print((1, "clubs", "cinnamon") < (1, "clubs", "vanilla"))
|
|
|
|
# O(N ^ 2)
|
|
|
|
|
|
# for i in range(10):
|
|
# print(i)
|
|
|
|
# iterable = range(4)
|
|
# iterator = iter(iterable)
|
|
# # print(dir(iterator))
|
|
# # print(iterator.__str__()[0])
|
|
# # print(iterator)
|
|
|
|
# # print(dir(iterator.__next__))
|
|
# print(next.__doc__)
|
|
|
|
# try:
|
|
# while True:
|
|
# print(iterator.__next__())
|
|
|
|
# except StopIteration:
|
|
# print("handled!")
|
|
|
|
[
|
|
"__class__",
|
|
"__delattr__",
|
|
"__dir__",
|
|
"__doc__",
|
|
"__eq__",
|
|
"__format__",
|
|
"__ge__",
|
|
"__getattribute__",
|
|
"__gt__",
|
|
"__hash__",
|
|
"__init__",
|
|
"__init_subclass__",
|
|
"__iter__",
|
|
"__le__",
|
|
"__length_hint__",
|
|
"__lt__",
|
|
"__ne__",
|
|
"__new__",
|
|
"__next__",
|
|
"__reduce__",
|
|
"__reduce_ex__",
|
|
"__repr__",
|
|
"__setattr__",
|
|
"__setstate__",
|
|
"__sizeof__",
|
|
"__str__",
|
|
"__subclasshook__",
|
|
]
|
|
|
|
# print(next(iterator))
|
|
# print(next(iterator))
|
|
# print(next(iterator))
|
|
# print(next(iterator))
|
|
# print(next(iterator))
|
|
|
|
|
|
# def sum_until(x: int) -> int:
|
|
# """computes the sum of number from 0 to x (inclusive)"""
|
|
|
|
# to_sum = list(range(x + 1))
|
|
# print(to_sum)
|
|
# s = 0
|
|
# for num in to_sum:
|
|
# s += num
|
|
# return s
|
|
|
|
|
|
# print(sum_until(3))
|
|
|
|
# from abc import ABC
|
|
# from dataclasses import dataclass
|
|
# from typing import List
|
|
|
|
|
|
# class Animal(ABC):
|
|
# def make_noise(self):
|
|
# pass
|
|
|
|
|
|
# @dataclass
|
|
# class Cat(Animal):
|
|
# name: str
|
|
|
|
# def make_noise(self):
|
|
# print("meow")
|
|
|
|
|
|
# class Lion(Cat):
|
|
# def hunt(self):
|
|
# print("nom")
|
|
|
|
|
|
# class Kitty(Cat):
|
|
# def make_noise(self):
|
|
# print("purr")
|
|
|
|
|
|
# animals: List[Animal] = [
|
|
# Kitty(name="Star Child"),
|
|
# Lion(name="Simba"),
|
|
# ]
|
|
# for animal in animals:
|
|
# animal.make_noise()
|