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 xml.etree.ElementTree import Element, tostring | |
def dict_to_xml(tag, d): | |
''' | |
Turn a simple dict of key/value pairs into XML | |
''' | |
elem = Element(tag) | |
for key, val in d.items(): | |
if type(val) == dict: |
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
# To be case-insensitive, and to eliminate a potentially large else-if chain: | |
m.lower().endswith(('.png', '.jpg', '.jpeg')) |
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 process_data(a, b, c, d): | |
>>> print(a, b, c, d) | |
>>> x = {'a': 1, 'b': 2} | |
>>> y = {'c': 3, 'd': 4} | |
>>> process_data(**x, **y) | |
1 2 3 4 | |
>>> process_data(**x, c=23, d=42) |
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 mt(a, memo=[]): | |
a += 1 | |
print(a) | |
memo.append(a) | |
print(memo) | |
mt(1) | |
mt(2) | |
mt(3) |
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
class DictDelta: | |
'''Returns a list of ḱeys, which are added, deleted or whose values have been altered compared to the dict passed in the previous call.''' | |
def __init__(self): | |
self.old_dict = None | |
def __call__(self, new_dict): | |
"""Returns list of changed keys.""" | |
# explicitly check for None, prevent all keys being returned on 1st run |
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
except ValueError as err: | |
err.strerror = "New error message" | |
raise err |
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
sudo xed ~/.netrc | |
machine github.com | |
login USER_NAME | |
password ACCESS_TOKEN | |
machine api.github.com | |
login USER_NAME | |
password ACCESS_TOKEN |
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
>>> a = 1 | |
>>> (a==1) + (a>0) + (a==2) | |
2 |
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
l = ['Your Code Here'] | |
t = ('Your Code Here') | |
for item in l: | |
print(item) | |
for item in t: | |
print(item) | |
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
git add * | |
git status -s | |
git commit -m "YOUR COMMIT MESSAGE" | |
git push origin feature_name |