Named-Arguments-In-Format

Sat 17 May 2025

title: "Named Arguments in Format" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


print("{greeting!r:20}".format(greeting="Hello"))
'Hello'
print("{one} {two!r}".format(one="ten", two="twenty"))
ten 'twenty'


Score: 0

Category: basics

Read More

Number Counter

Sat 17 May 2025

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"
content
'one 2 1 three 4 2 1 …

Category: basics

Read More

Pass By Ref Test

Sat 17 May 2025

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')
list = ['one', 'two']
add_to_list(list)
print(list)
['one', 'two', 'three']

Key takeaway:

1- You can use the reference that a function receives as its arguments, to modify the …

Category: basics

Read More

Prettify-Xml

Sat 17 May 2025

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()
pretty_xml_as_string
'<?xml version="1.0" ?>\n<note>\n\t\n …

Category: basics

Read More

Pretty Print Json

Sat 17 May 2025

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 …

Category: basics

Read More

Pretty Print Online Json

Sat 17 May 2025

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 …

Category: basics

Read More

Py-Ml-Tips-Rules

Sat 17 May 2025

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 …

Category: basics

Read More

Pylru-Cache

Sat 17 May 2025

title: "Pylru Cache" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import pylru
cache = pylru.lrucache(100)
cache
<pylru.lrucache at 0x112997fd0>
# add 
cache['name'] = 'One'
cache['name']
'One'
# add 
cache['city'] = 'Toronto'
'city' in cache # this doesn't affect the cache order
True
cache.keys()
<generator object lrucache …

Category: basics

Read More

Python-Division

Sat 17 May 2025

title: "Python Division" author: "TACT" date: 2019-04-20 description: "-" type: technical_note draft: false


a = 30
b = 6

c = a / b
print(c)
5.0


Score: 0

Category: basics

Read More

Python Path

Sat 17 May 2025

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 …

Category: basics

Read More
Page 10 of 17

« Prev Next »