Answer to the previous exercise. http://xahlee.org/perl-python/generate_pairings.html # perl sub genpair ($) { my $partiSet = $_[0]; my @result; for (my $head...
I have a bunch of files encoded in gb18030 and i need to convert it to utf-16. Can i do that with Pyton? Yes. Such facilities is built-in in Python version...
Is it possible in Python to create a function that maintains a variable value? Something like this: globe=0; def myFun(): globe=globe+1 return globe The answer...
here's the code. ... # python import os mydir= '/Users/t/web/p/monkey_king' def changeEncoding(filePath): '''take a full path to a file as input, and change...
here's a large exercise that uses what we built before. suppose you have tens of thousands of files in various directories. Some of these files are identical,...
previously we had find & replace string in a file: http://xahlee.org/perl-python/find_replace.html though, that code won't work for non-ascii files. For...
python has this nice unicodedata module that deals with unicode nicely. #-*- coding: utf-8 -*- # python from unicodedata import * # each unicode char has a...
here's a snippet of code that prints a range of unicode chars, along with their ordinal in hex, and name. chars without a name are skipped. (some of such are...
... l=[] for i in range(0x0000, 0x0fff): l.append(eval('u"\\u%04x"' % i)) ... can be simplified to: for x in map (unichr, xrange(0x0000, 0x0fff)): - Sean...
Sorry i've been busy... Here's the Perl code. I have yet to clean up the code and make it compatible with the cleaned spec above. The code as it is performs...
Today we'll write a program that can sort a matrix in all possible ways. Here's the Perl documentation. I'll post a Perl and Python version in 2 days. ... ...
The Python doc is relatively lousy, from content organization to the tech writing quality. I think i'll just post snippets of my comments as i find them. (and ...
Here's the solution to previous post. ... perl code: sub sort_matrix($$) { my $ref_matrix = $_[0]; my @indexMatrix = @{$_[1]}; my @indexes = map {$_->[0]}...
According to the Python documentation* for 'sort', supplying a function for generating keys generally runs faster than supplying a function for comparing...
I get: NameError: global name 'reversed' is not defined ... ? I don't quite follow the logic... Xah ... On Mar 28, 2005, at 11:14 AM, Sean Gugler wrote: ...
The 'reversed' function was introduced with Python 2.4. Older versions may instead use: directives.reverse() for (column, stringQ, directionQ) in directives: ...
i've updated the previous find & replace code. in the following page http://xahlee.org/perl-python/findreplace_regex.html is a code that does find & replace of...
20050415 split a line by regex Here's another example of using regex. I have a file that is translation of Chinese lyrics. It is formatted like this: ...
Unicode chars can be included in regex patterns directly. Just make sure your string starts with ur. For example: re.search(ur'苦',mystring,re.U). Unicode can...
long story short, here's a complete rewrite of Python's re module doc http://xahlee.org/perl-python/python_re-write/lib/module-re.html This documentation...
Notes on rewriting the Python documentation Xah Lee, 200505. In 2005, i started to learn Python by reading its official documentation. In the process, i find...
HTML Problems in Python Doc I don't know what kind of system is used to generate the Python docs, but it is quite unpleasant to work with manually, as there...
Today we'll be writing a function called Range. The Perl documentation is as follows. Perl & Python & Java Solutions will be posted in 48 hours. Perl-Python...
Here's the Perl solution to the Range problem. ... # perl # http://xahlee.org/tree/tree.html # Xah Lee, 2005-05 #_____ Range _____ _____ _____ _____ =pod ...
The following is a new section of the article “What are OOP's Jargons and Complexities” at http://xahlee.org/Periodic_dosage_dir/t2/oop.html ... The Rise...
The following is a new section of the article “What are OOP's Jargons and Complexities” at http://xahlee.org/Periodic_dosage_dir/t2/oop.html ... The Rise...
The following is a new section of the article “What are OOP's Jargons and Complexities” at http://xahlee.org/Periodic_dosage_dir/t2/oop.html ... the Rise...