xtodo python
Math of Ordering
In general, the function f used to determine the order of any two element must satisfy some constraints:
- f(a,a)==0
- if f(a,b)==0 then f(b,a)==0
- if f(a,b)==0 and f(b,c)==0, then f(a,c)==0.
- if f(a,b)==-1 and f(b,c)==-1, then f(a,c)==-1.
- if f(a,b)==-1, then f(b,a)==1.
If the comparison function does not behave as the above, then it is not consistent. It means that the result ordered list may actually be different depending the order of the original list or how the language happens to implement sort.
The significance of all this is that in real software you may want to sort a list of complex object by a specialized ordering. e.g. you may want to sort a list of triangles in 3D space by their orientation. Or, sorting image selections in a photo-editing program. It is in advanced cases like these, understanding the basic math about ordering is important. Otherwise, you might have a inconsistent result yet unable to locate any flaws in your code.
The order-deciding function given by the user is called a “predicate” in computer science. (A predicate function is any function that returns either true or false) And, it is usually defined inline using a pure function construct called “lambda”.
dion's try at WolframLang's Map
def map_at_depth(func, node, depth, target_depth, get_children): if target_depth < depth: return else if target_depth == depth: yield func(node) for child in get_children(node): yield from map_at_depth(func, child, depth+1, target_depth, get_children)
WHAT DOES THIS MEANS EXACTLY? :
Empty matches for the pattern are replaced only when not adjacent to
a previous match, so "sub('x*', '-', 'abc')" returns
'-a-b-c-'
.
In addition to character escapes and backreferences as described above, \g<name>
will use the substring matched by the group named name
, as defined by the (?P<name>…)
syntax. \g<number>
uses the corresponding group number; \g<2>
is therefore equivalent to \2
, but isn't ambiguous in a replacement such as \g<2>0
. \20
would be interpreted as a reference to group 20, not a reference to group 2 followed by the literal character 0
.
The backreference \g<0>
substitutes in the entire substring matched by the pattern.
- 2022-01-12 blog this python print unicode to stdout
sys.stdout.reconfigure(encoding='utf-8')
# python 3 import sys sys.stdout.reconfigure(encoding="utf-8") print(sys.stdout.encoding) # 2022-01-11 need to get python to print unicode and shows as char, when run in emacs print("unicode • BULLET")
xx = " TypeScript Tutorial Deno: Intro By Xah Lee. Date: 2022-10-18. Deno is a great JavaScript compiler, TypeScript compiler, and runtime engine. With Deno, you can run JavaScript or TypeScript like a shell script in terminal. Deno is created by Ryan Dahl, the same guy who created node.js in 2009. but nodejs became corrupt over the years, so Ryan Dahl created created a better version called deno in 2018. Download and Install Deno Download Deno at https://deno.land/ run deno interactively Type deno to start the interactive prompt. Type Ctrl+d to exit. deno js 2022-06-13 5cv36 deno js 2022-06-13 5cv36 run deno as as shell script deno run test.js Run Deno in Emacs For emacs users, you can eval the JavaScript code in a buffer directly. See: Emacs: Run Current File 🚀 TypeScript TypeScript Install TypeScript Filename Extension TypeScript: Convert to JavaScript TypeScript: Errors TypeScript Misc Notes deno Deno: Intro Deno: Print Version Deno: Ignore Format " xlist= xx.split() print( max(set(zip(xlist,xlist[1:])), key=xlist.count) ) # you just said find the most common bigram # dict of word + count: {w: xlist.count(w) for w in set(xlist)} # sorted dict of word + count: from collections import OrderedDict OrderedDict((w,xlist.count(w)) for w in sorted(set(xlist)))
- 2022-10-14 review Python: How to Write a Module , maybe combine with Python: Import Module
- 2022-10-09 review code Python: Convert File Encoding
- 2022-09-04 Python: Regex Syntax
- 2022-07-31 Python Regex re.findall TODO: need another example here showing what is meant by “unless they touch the beginning of another match.”
- Python: Regex Functions
- 2022-01-29 perl move Perl: Delete Duplicate Image Files and maybe put code up
