I hereby claim:
- I am juanarrivillaga on github.
- I am juan_arrivillaga (https://keybase.io/juan_arrivillaga) on keybase.
- I have a public key ASC5d4e7y9NLx-4klf4eye68-G8TDCtBlo08KzAUwzX2pwo
To claim this, I am signing this object:
import collections | |
def drop(iterable, n): | |
iterator = iter(iterable) | |
buffer = collections.deque() | |
for _ in range(n): | |
try: | |
val = next(iterator) | |
except StopIteration: | |
return |
I hereby claim:
To claim this, I am signing this object:
class Settings: | |
def __init__(self): | |
self.settingsID = 1 |
>>> import dis | |
>>> def regular_loop(source): | |
... result = [] | |
... for x in result: | |
... result.append(x**2) | |
... return result | |
... | |
>>> def list_comp(source): | |
... result = [x**2 for x in source] | |
... return result |
import pandas as pd | |
import matplotlib.pyplot as plt | |
import time | |
def filter_items_newlist(items, item): | |
return [x for x in items if x != item] | |
def filter_items_inplace_gen(items, item): | |
items[:] = (x for x in items if x != item) |
# note, using the %%timeit ipython magic, the expression on the first line is not included in the time testing | |
In [3]: %%timeit items = list(map(str, range(1))) | |
...: 'foo' in items | |
...: | |
...: | |
33 ns ± 1.79 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each) | |
In [4]: %%timeit items = set(map(str, range(1))) | |
...: 'foo' in items |
import types | |
class Function: | |
def __init__(self, func): | |
self._func = func | |
def __call__(self, *args, **kwargs): | |
return self._func(*args, **kwargs) | |
def __get__(self, obj, objtype=None): | |
"Simulate func_descr_get() in Objects/funcobject.c https://docs.python.org/3/howto/descriptor.html#functions-and-methods" | |
if obj is None: | |
return self |
class Server(object): | |
def __init__(self, ip_address, username, password, port): | |
self.ip_address = ip_address | |
self.username = username | |
self.password = password | |
self.port = port | |
self.update_base_url(ip_address, port) | |
def update_base_url(self, ip_address, port): | |
base_url = 'https://' + str(ip_address) + ':' + str(port) + '/' | |
self.base_url = base_url |
You are looking for the built-in `dict` data-type. However, keys must be *hashable* objects. | |
Python prevents you from shooting yourself in the foot by using a mutable object as a key | |
(although, you can implement your own data-type which is mutable and hashable, but you *shouldn't*). | |
Note, consider the following JS code: | |
> m1 = new Map([['a', 1]]) | |
Map { 'a' => 1 } | |
> m2 = new Map() | |
Map {} | |
> m2.set(m1, 3) |
# You can alleviate the nesting by using `and`, since your `else` statements are all equivalent up to a point | |
if (preset.exists('//*[@id="i0116"]', '10', '1') and log.enter_username() | |
and preset.exists('//*[@id="i0116"]', '10', '1') and log.enter_password()): | |
locked = unlock(details[0], details[1], browser, ' ', ' ', ' ') | |
if not (locked.checkBlocked()): | |
# unlock account | |
else: | |
searches = search(details[0], details[1], browser) | |
else: | |
browser.quit() |