Read-Text-File-Online
title: "Read Text File Online"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
import urllib.request, json
data = None
with urllib.request.urlopen("https://gitlab.com/rajacsp/datasets/raw/master/gandhi.txt") as url:
data = url.read().decode()
'Mahatma Gandhi has been variously described as an …
Read More
Read-With-Unicode-Escape
title: "Read Online CSV with Unicode Escape"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
'''
https://stackoverflow.com/questions/22216076/unicodedecodeerror-utf8-codec-cant-decode-byte-0xa5-in-position-0-invalid-s
'''
'\nhttps://stackoverflow.com/questions/22216076/unicodedecodeerror-utf8-codec-cant-decode-byte-0xa5-in-position-0-invalid-s\n'
from io import BytesIO
import requests
import pandas as pd
filename = 'https://www.sample-videos.com/csv/Sample-Spreadsheet-10-rows.csv'
r …
Read More
Recursion
import pyutil as pyu
pyu.get_local_pyinfo()
'conda env: ml311; pyv: 3.11.10 (main, Oct 3 2024, 07:29:13) [GCC 11.2.0]'
print(pyu.ps2("haystack-ai ollama-haystack python-dotenv"))
haystack-ai==2.8.0
ollama-haystack is not installed in the current environment.
python-dotenv==0.21.0
Read More
Reduce
title: "Reduce"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
from functools import reduce
def add(a, b):
return a + b
reduce(add, [10, 20, 30, 40])
Score: 5
Read More
Reduce-Advanced
title: "Reduce Advanced"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
from functools import reduce
def do_magic(a, b):
if((a % 2 == 1) & (b % 2 == 1) ):
return a * b
return a + b
reduce(do_magic, [10, 20, 30, 40])
Read More
Reducer
title: "Reducers"
author: "Rj"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
list = [10, 40, 20, 50, 30, 90]
sum_list = fnt.reduce(lambda x, y: x+y, list)
def get_sum(list):
return fnt.reduce(lambda x,y : x …
Read More
Regex-Groups
title: "Regex Groups"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
names = ['A2B8']
for name in names:
m = re.match("^[A-Z]\d[A-Z]\d", name)
if(m):
print(m.groups())
print('matched : ', name)
Score: 0
Read More
Regexp-Stemmer
title: "Regexp Stemmer"
author: "Rj"
date: 2019-04-21
description: "-"
type: technical_note
draft: false
from nltk.stem import RegexpStemmer
re_stemmer = RegexpStemmer("ing$|s$|e$|able$", min=7)
words = [
"wheels",
"breaking",
"thrones",
"breakable"
]
['wheels', 'breaking', 'thrones', 'breakable']
result = [re_stemmer.stem(word) for word in words]
['wheels', 'break', 'throne', 'break']
As the …
Read More
Remove Item On Loop
title: "Remove Item on Loop"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
list = [
1, 2, 3, 4, 5, 6
]
# remove even entries while looping
for i, j in enumerate(list):
print(i, j)
Read More