This file contains 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 filter(func, iterable): | |
return [el for el in iterable if func(el)] | |
def map(func, iterable): | |
return [func(x) for x in iterable] | |
def reduce(func, iterable, init=None): | |
it = iter(iterable) | |
val = next(it) if init is None else init |
This file contains 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
class Meta(type): | |
def __new__(cls, what, bases=None, dict=None): | |
if 'area' not in dict: | |
raise Exception("Area not found!") | |
return type.__new__(cls, what, bases, dict) | |
class Shape(metaclass=Meta): | |
def __init__(self, l, w): | |
self.l = l | |
self.w = w |
This file contains 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
_='_=%r;print (_%%_)';print (_%_) |
This file contains 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 time | |
import functools | |
class Foo: | |
def __init__(self, n = 1): | |
self.n = n | |
@functools.cached_property | |
def expensive(self): | |
return fib(self.n) |
This file contains 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 diff_a(a, b): | |
return list(set(a) - set(b)) + list(set(b) - set(a)) | |
def diff_b(lists): | |
x = [list(set(i) - set(j)) for i in lists for j in lists] | |
return list(set([item for sublist in x for item in sublist])) | |
def main(): | |
a = [1, 2, 3]; b = [1, 2, 5, 4]; c = [1, 3, 5, 6] | |
print(diff_a(a, b)) # [3, 5, 4] |
This file contains 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
# python functions are objects | |
# can be passed stored in variables, passed as args, returned, etc | |
def wrap(func): | |
print("wow!") | |
func() | |
print("oo") | |
def hello(): | |
print("hello!") |
This file contains 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
using System; | |
using System.Collections.Generic; | |
class Program { | |
static void Main(string[] args) { | |
List<List<int>> arr = new List<List<int>>(); | |
// -> [] | |
for(int i = 0; i < 10; ++i) { |
This file contains 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
using System; | |
using static System.Console; | |
class Program { | |
static void Main(string[] args) { | |
Write("Number of rows: "); | |
int r = int.Parse(ReadLine()); // 5 | |
Write("\nNumebr of cols: "); | |
int c = int.Parse(ReadLine()); // 3 |
This file contains 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 typing import List | |
R, C = 3, 3 | |
def construct(board: List[List[int]]) -> str: | |
""" | |
Constructs a tic tac toe board string based | |
on a 2D list |
