Geo Location 1

Sat 17 May 2025

title: "Geo Location 1" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import requests
import json 
send_url = 'http://api.ipstack.com/50.100.30.136?access_key=49ad529d309a09477749245782d260b8&format=1'
r = requests.get(send_url)
j = json.loads(r.text)

lat = j['latitude']
lon = j['longitude']
print(lat)
print(lon)
43 …

Category: basics

Read More

Geo Location 2

Sat 17 May 2025

title: "Geo Location by Geocoder" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import geocoder
g = geocoder.ip('me')
print(g.latlng)
[43.6909, -79.3098]
test_location = geocoder.ip('151.101.1.69')
print(test_location.latlng)
[37.751, -97.822]


Score: 5

Category: basics

Read More

Get Attribute

Sat 17 May 2025

title: "Get Attribute" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


import sys
print(getattr(sys, 'version'))
3.6.8 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46) 
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]


Score: 0

Category: basics

Read More

Get Default Encoding

Sat 17 May 2025

title: "Get Default Encoding" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import sys
print(sys.getdefaultencoding())
utf-8

Score: 0

Category: basics

Read More

Get-Encoding

Sat 17 May 2025

title: "Get Encoding" author: "Rj" date: 2019-04-20 description: "-" type: technical_note draft: false


import sys
print(sys.getdefaultencoding())
utf-8


Score: 0

Category: basics

Read More

Get Int Input

Sat 17 May 2025

title: "Get Int Input" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


x = int(input("Enter a number: "))
y = int(input("Enter a number: "))

print((x+y))
Enter a number: one



---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

<ipython-input-2-d1355a0ae898> in <module>()
----> 1 x = int(input …

Category: basics

Read More

Get-Value-And-Check-1

Sat 17 May 2025

DATA                              = "data"
JSON_DATA                         = "jsonData"
PENALIZATION_IMPUTATION_WEIGHTAGE = "penalizationImputationWeightage"
mltrainconfig_json = {
    "data" : {
        "jsonData" : {
            "penalizationImputationWeightage" : {
                "one" : "two"
            }
        }
    }
}
penalization_imputation_weightage = mltrainconfig_json.get(DATA, {})\
        .get(JSON_DATA, {})\
        .get(PENALIZATION_IMPUTATION_WEIGHTAGE, {})
penalization_imputation_weightage = penalization_imputation_weightage if penalization_imputation_weightage else imputing_factor_value
penalization_imputation_weightage
{'one': 'two'}



mltrainconfig_json = {
    "data" : {
        "jsonData" : {
            "penalizationImputationWeightage2" : {
                "one" : "two"
            }
        }
    }
}
imputing_factor_value = {
    "eleven" : "twelve"
}
penalization_imputation_weightage = mltrainconfig_json.get(DATA, {})\
        .get(JSON_DATA, {})\
        .get(PENALIZATION_IMPUTATION_WEIGHTAGE, {})
penalization_imputation_weightage
{}
penalization_imputation_weightage = penalization_imputation_weightage if …

Category: basics

Read More

Hex-Validator

Sat 17 May 2025

import re

def is_valid_hex_color(color):
    pattern = r'^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$'
    return bool(re.match(pattern, color))

# Examples
print(is_valid_hex_color("#FFF"))  # True
print(is_valid_hex_color("#123ABC"))  # True
print(is_valid_hex_color("#123ABCG"))  # False
True
True
False
!pip show webcolors | grep "Version:"
Version: 24.11.1

import webcolors

def is_valid_hex_color(color):
    try:
        webcolors.hex_to_rgb …

Category: basics

Read More

Immutable-Int

Sat 17 May 2025

title: "Immutable Int" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


a = 12

dictionary = {
  "one": a
}
a
12
dictionary
{'one': 12}
a += 9
a
21
dictionary
{'one': 12}

int is immutable, that's why you can't see the dictionary value changed

Here you are assigning to key 'a' …

Category: basics

Read More

Index Remover

Sat 17 May 2025

"""
input sample:
17. random text1
18. random text2

output:
17, random text1
18, random text2
"""
'\ninput sample:\n17. random text1\n18. random text2\n\noutput:\n17, random text1\n18, random text2\n'
input_sample = """
17. random text1
18. random text2
"""

# Process the input sample
output = []
for line in input_sample.strip().split …

Category: basics

Read More
Page 6 of 17

« Prev Next »