E

@esteban03

cycles_agents.py

Python
1 year ago
def detect_agent_cycles(interactions, cycle_length=2): """ Detecta ciclos repetitivos entre agentes basados en las interacciones. :param interactions: Lista de tuplas (agente_origen, agente_destino) :type interactions: list :param cycle_length: Longitud mínima del ciclo a detectar :type cycle_length: int

ceruccho.py

Python
1 year ago
def cerrucho(items=[]): items.sort() items1 = items[::2] items2 = items[1::2]

uppecase_every_word.py

Python
1 year ago
def uppercase(text): words = [w.capitalize() for w in text.split()] return " ".join(words) text = uppercase("Hola como estas tu hoy") print(text)

calcular_cuota_hipotecaria

Python
1 year ago
def calcular_cuota_hipotecaria(monto_credito, tasa_interes_anual, plazo_anos): # Convertir la tasa de interés anual a tasa mensual tasa_interes_mensual = tasa_interes_anual / 12 / 100 # Número total de pagos (meses) n = plazo_anos * 12 # Calcular la cuota mensual usando la fórmula cuota_mensual = monto_credito * tasa_interes_mensual * (1 + tasa_interes_mensual) ** n / ((1 + tasa_interes_mensual) ** n - 1)

minimumswaps

Python
2 years ago
def minimumSwaps(arr): positions = {value: index for index, value in enumerate(arr)} counter = 0 last_index = 0 while True: swaps = False

bribes

Python
2 years ago
def minimumBribes(q): # Can only bribe to move forward. We can take a greedy approach where we sort the # queue from the back, and only allow swaps within a specified window # if, by the end of the sort within each window, the last element is not in position, # it means they made too many bribes n = len(q) window = 3

enumerate things

Python
2 years ago
books = [("Dan brown", "Davinci Code"), ("Bram Stoker", "Dracula"), ("Murakami", "Tokio Blues")] def a(): index = 1 for item in books: author, book = item print(f"{index}: {book} by {author}")

Common elements

Python
2 years ago
l = [1,2,3,4,5] m = [1,3,4,5,10,8] commmon_elements = [] def a(): for li in l:

algorithms

Python
2 years ago
s = "cfimaakj" n = 554045874191 lenght_s = len(s) to_repeat = n / lenght_s quantity_of_a_in_s = s.count("a")

prueba entrevista

Python
2 years ago
line = 'Hello world!' new_words = [] for word in line.split(): new_word = "" fisrt = True

ejemplo rapido

Python
4 years ago
def t(): return dict(a=1) l = t() s = t()

how to easily know when is the last element inside a loop

Python
4 years ago
from typing import Union, Set, List, Tuple, Any Vectors = Union[Tuple, List, Set] # create this function def lookthelast(items: Vectors) -> Tuple[Any, bool]: lenght_items = len(items) for index, value in enumerate(items):

cuidado! evita esto en python

Python
5 years ago
import json def decode(data, default={}): try: return json.loads(data) except ValueError: return default

Abstracción python

Python
6 years ago
import abc class ImplementacionInterface(abc.ABC): @abc.abstractmethod def imp1(self): pass

sub listas

Python
6 years ago
lista = [1,2,3,4,5] sub = lista[::-1] print(sub)

inmutabilidad en python

Python
6 years ago
class Constantes: @property def CONSTANTE(self): return 'propiedad' c = Constantes()

315. Count of Smaller Numbers After Self

Python
6 years ago
import bisect def countSmaller(nums): counts = [] done = [] for num in nums[::-1]: counts.insert(0, bisect.bisect_left(done, num)) bisect.insort(done, num) return counts