Named-Arguments-In-Format
title: "Named Arguments in Format"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
print("{greeting!r:20}".format(greeting="Hello"))
print("{one} {two!r}".format(one="ten", two="twenty"))
Score: 0
Read More
Number Counter
title: "Number Counter"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
source: https://www.accelebrate.com/blog/using-defaultdict-python/
from collections import defaultdict
counter = defaultdict(int)
content = "one 2 1 three 4 2 1 7 6 six 8 9 8"
Read More
Pass By Ref Test
title: "Pass by Ref Test"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
def add_to_list(list):
list.append('three')
Key takeaway:
1- You can use the reference that a function receives as its arguments, to modify the …
Read More
Prettify-Xml
title: "Prettify XML"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
import xmltodict
import pprint
import json
import xml.dom.minidom
dom = xml.dom.minidom.parse('sample.xml') # or xml.dom.minidom.parseString(xml_string)
pretty_xml_as_string = dom.toprettyxml()
'<?xml version="1.0" ?>\n<note>\n\t\n …
Read More
Pretty Print Json
title: "Pretty Print Json"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
import json
import pprint
content = """{"system": {"commit": None, "python": "3.6.8.final.0", "python-bits": 64, "OS": "Darwin", "OS-release": "18.5.0", "machine": "x86_64", "processor": "i386", "byteorder": "little", "LC_ALL": "None", "LANG": "en_CA.UTF-8", "LOCALE": "en_CA …
Read More
Pretty Print Online Json
title: "Pretty Print Online JSON"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
import pprint
import json
from urllib.request import urlopen
r = urlopen("https://mdn.github.io/fetch-examples/fetch-json/products.json")
text = r.read()
pprint.pprint(json.loads(text))
{'products': [{'Location': 'Refrigerated foods',
'Name': 'Cheese',
'Price …
Read More
Py-Ml-Tips-Rules
title: "Py ML Tips and Rules"
author: "Rj"
date: 2019-04-21
description: "-"
type: technical_note
draft: false
Numpy Indexing
Numpy indexing for one-dimensional arrays works similarly to Python lists using the square-bracket notation. For two-dimensional arrays, the first index refers to the row number, and the indexer to the column number.
Score …
Read More
Pylru-Cache
title: "Pylru Cache"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
cache = pylru.lrucache(100)
<pylru.lrucache at 0x112997fd0>
# add
cache['name'] = 'One'
# add
cache['city'] = 'Toronto'
'city' in cache # this doesn't affect the cache order
<generator object lrucache …
Read More
Python-Division
title: "Python Division"
author: "TACT"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
Score: 0
Read More
Python Path
title: "Python Path"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
import sys
print(sys.path)
['', '/Users/rajacsp/anaconda3/envs/py36/lib/python36.zip', '/Users/rajacsp/anaconda3/envs/py36/lib/python3.6', '/Users/rajacsp/anaconda3/envs/py36/lib/python3.6/lib-dynload', '/Users/rajacsp/anaconda3/envs/py36/lib/python3.6 …
Read More