# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website #...
it's interesting to note that the string replace method .replace() does so by returning a copy, as opposed to inplace. in OOP parlance, such would be called...
previously we had a code that find & replaces strings in a dir. http://xahlee.org/perl-python/find_replace_dir.html now suppose in your html file, you want to...
20050207 text pattern matching # -*- coding: utf-8 -*- # Python # suppose you want to replace all strings of the form # <img src="some.gif" width="30"...
a year ago i wrote this perl program as part of a larger program. as a exercise of fun, let's do a python version. I'll post my version later today. # combo(n)...
# -*- coding: utf-8 -*- # Python # David Eppstein of the Geometry Junkyard fame gave this elegant # version for returing all possible pairs from a range of n...
here's a interesting real-world algoritm to have fun with. attached below is the Perl documentation that i wrote for a function called “reduce”, which is...
here are the solutions: Perl code: sub reduce ($$) { my %hh= %{$_[0]}; # e.g. {'1,2'=>[1,2],'5,6'=>[5,6],...} my ($j1,$j2)=($_[1]->[0],$_[1]->[1]); # e.g....
someone supplied this version of reduce: def reduce2( pairings, pair ): result={} for i,j in pairings.itervalues(): if i in pair: i=pair[0] if j in pair:...
... That was me, formerly reading posts via web and now joining the group at the encouragement of Mr. Lee to continue this discussion. ... the ... Thanks!...
here's another interesting algorithmic exercise, again from part of a larger program in the previous posts. Here's the original Perl documentation: =pod ...
here's the answer to yesterday's exercise. ... # Perl code sub merge($) { my @input = @{$_[0]}; my @interm; # array of hashs # chop the first value of @input...
previously we had scripts that replace strings for all files in a dir. See http://xahlee.org/perl-python/findreplace_multi_pairs.html i modified the script and...
another functional exercise with lists. Again, it is part of a larger program. I'm proceeding to port the whole thing to Python as a exercise. We've done about...
(previous post is crude and sloppy filled with errors. Here's a better, corrected version.) ... another functional exercise with lists. Here's the perl...
[SOLUTIONS BELOW] I suspect you are looking for an answer that makes use of the previous exercises, like so: def parti (list, equalFunc): n = len(list) equals...
Here's the answer to the generic equivalence partition exercise. http://xahlee.org/perl-python/gen_parti_by_equiv.html # the following solution is submitted by...
the parti one gives incorrect answer for li=[4, 4, 1, 1, 2, 0, 0, 1, 3], with == as predicate.) The parti_custom looks great. Thanks. Xah Lee ... On Feb 24,...
20050226 exercise: generate all possible pairings given a list that is a set partitioned into subsets, generate a list of all possible pairings of elements in...
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...