Python Programming using Unicode

Code काहीनाही = None लिहा = print class सूर: def __init__(स्वतः, नाव): स्वतः.नाव = नाव स्वतः._वाहन = काहीनाही def माहिती(स्वतः): return {'नाव': स्वतः.नाव, 'वाहन': स्वतः.वाहन} @property def वाहन(स्वतः): return स्वतः._वाहन @वाहन.setter def वाहन(स्वतः, मूल्य): स्वतः._वाहन = मूल्य अनेक_सूर = [ सूर('पार्वती') सूर('गणपती'), सूर('शंकर'), सूर('कार्तिक') ] अनेक_सूर[0].वाहन = 'वाघ' अनेक_सूर[1].वाहन = 'मूषक' अनेक_सूर[2].वाहन = 'बैल' अनेक_सूर[3].वाहन = 'मोर' for एक_सूर in अनेक_सूर: लिहा(एक_सूर.नाव, '->', एक_सूर.वाहन) लिहा(एक_सूर.माहिती()) Output पार्वती -> वाघ {'नाव': 'पार्वती', 'वाहन': 'वाघ'} गणपती -> मूषक {'नाव': 'गणपती', 'वाहन': 'मूषक'} शंकर -> बैल {'नाव': 'शंकर', 'वाहन': 'बैल'} कार्तिक -> मोर {'नाव': 'कार्तिक', 'वाहन': 'मोर'}

जानेवारी 16, 2023 · 1 min · 94 words · शंतनू

Split Indic Words

Python Code import unicodedata def split_clusters(txt): """ Generate grapheme clusters for the Devanagari text.""" cluster = u'' end = False for char in txt: category = unicodedata.category(char) if (category == 'Lo' and end ) or category[0] == 'M': cluster = cluster + char else: if cluster: yield cluster cluster = char end = unicodedata.name(char).endswith(' SIGN VIRAMA') if cluster: yield cluster Go Code import ( "strings" "unicode" "golang.org/x/text/unicode/runenames" ) func splitClusters(txt string) (ret []string) { cluster := "" end := false for _, x := range txt { if (unicode....

जानेवारी 9, 2023 · 1 min · 150 words · शंतनू

Python packaging with cython

cython converts python code to C/C++ and creates compiled extensions. Generally this is used to speed up the execution, but one can also use it for protecting their python source code. Code structure package_tutorial +- setup.py +- README.md +- my_pkg +- __init__.py +- module_one.pyx +- module_two.pyx +- utils.pyx # __init__.py from . import utils from . import module_one from . import module_two # utils.py def add(a, b): return a+b # module_one....

एप्रिल 17, 2021 · 1 min · 170 words · शंतनू

Fizz Buzz

Problem: Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”. f = lambda x: 'FizzBuzz' if not (x%5 or x%3) else 'Fizz' if not x%3 else 'Buzz' if not x%5 else str(x) for x in range(100): print(f(x)) Fizz Buzz problem

एप्रिल 22, 2014 · 1 min · 73 words · शंतनू

Using timezone with datetime in python

>>> import pytz >>> import datetime >>> tz = pytz.timezone('Asia/Calcutta') >>> tz <DstTzInfo 'Asia/Calcutta' HMT+5:53:00 STD> >>> t = tz.localize(datetime.datetime(2014, 4, 5, 6, 7, 8, 900)) >>> t datetime.datetime(2014, 4, 5, 6, 7, 8, 900, tzinfo=<DstTzInfo 'Asia/Calcutta' IST+5:30:00 STD>) >>> t.isoformat() '2014-04-05T06:07:08.000900+05:30' Reference: Python datetime object show wrong timezone offset

एप्रिल 5, 2014 · 1 min · 50 words · शंतनू