<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<link rel="self" href="/Atom/" />
	<id>http://billmill.org/</id>
	<title>My Name Rhymes</title>
	<subtitle>Bill Mill blogs irregularly</subtitle>
	<updated>2010-04-29T21:10:00Z</updated>
	<author>
		<name>Bill Mill</name>
		<email>bill.mill@gmail.com</email>
		<uri>http://billmill.org/</uri>
	</author>
	<link href="http://billmill.org/" />
	<entry>
		<title>Visualizing Permutations</title>
		<link href="http://billmill.org/permvis.html" />	
		<id>http://billmill.org/permvis.html</id>
		<updated>2010-04-29T21:10:00Z</updated>
		<summary type="html">&lt;p&gt;At some point a few years ago, I got interested in permutation algorithms and
implemented a few that were in Knuth as well as gathered some that were
floating around the internet. I never did anything with them, until I saw Aldo
Cortesi's excellent &lt;a
href="http://corte.si/posts/code/visualisingsorting/index.html"&gt;sorting
visualizations&lt;/a&gt; which reminded me of &lt;a
href="http://img.skitch.com/20100429-muthj97xmh8a34dnwnqkc64d6e.jpg"&gt;a figure
from Knuth&lt;/a&gt;, and inspired me to create some visualizations of my own using
Aldo's code.

&lt;p&gt;&lt;h2&gt;Lexicographic Permutations&lt;/h2&gt;

&lt;p&gt;Informally, the permutations of a set are all possible orderings of its
members. The permutations of the set &lt;i&gt;{1,2,3}&lt;/i&gt;, are: 

&lt;p&gt;&lt;code&gt;[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]&lt;/code&gt;

&lt;p&gt;This particular ordering of permutations is in &lt;i&gt;lexicographic order&lt;/i&gt;;
it's listed in the same order as it would be in the dictionary. There are many
well-known algorithms for generating permutations in lexicographic order. &lt;a
href="http://github.com/llimllib/personal_code/blob/master/python/permutation/permute.py#L5"&gt;Here&lt;/a&gt;
is my version of one such algorithm; &lt;a
href="http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz"&gt;go read Knuth&lt;/a&gt;
if you're at all interested in learning more.

&lt;p&gt;Here's what a lexicographic permutation of four elements looks like:

&lt;p&gt;&lt;img src="http://billmill.org/static/perm1.png"&gt;

&lt;p&gt;It's easy to see that each element gets its turn at the top of the list, and
that each time a new element goes to the top the remainder of the list is
sorted.

&lt;p&gt;&lt;h2&gt;Single-transposition Permutations&lt;/h2&gt;

&lt;p&gt;It is an interesting and non-obvious fact that there's a way to permute any
given set by only switching the positions of one pair of elements per iteration.
This permutation is deeply related to the &lt;a
href="http://en.wikipedia.org/wiki/Gray_code"&gt;Gray code&lt;/a&gt;, which if you
haven't heard of, I highly recommend you go read about. The Knuth &lt;a
href="http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz"&gt;paper&lt;/a&gt; I
mentioned aleady has a superb bit on the Gray code.

&lt;p&gt;&lt;img src="http://billmill.org/static/perm4.png"&gt;

&lt;p&gt;This image demonstrates clearly that at each step, there is exactly one
crossing. My implementation of this algorithm is &lt;a
href="http://github.com/llimllib/personal_code/blob/master/python/permutation/permute.py#L201"&gt;also
on github.&lt;/a&gt;

&lt;p&gt;&lt;h2&gt;CLP Permutation&lt;/h2&gt;

&lt;p&gt;I know very little about this algorithm, except that I got it from &lt;a
href="http://mail.python.org/pipermail/python-list/2002-November/170393.html"&gt;a message
to comp.lang.python&lt;/a&gt; where it's attributed to Alex Martelli, Duncan Smith,
and somebody named Anton (Anton Vredegoor?). Despite the crazy number of
switches, and the fact that it reorders the list it's passed, it's actually
crazy fast.

&lt;p&gt;&lt;img src="http://billmill.org/static/clp_perm.png"&gt;

&lt;p&gt;I'd love to hear from anyone with more info on this algorithm; my slightly
modified version is &lt;a
href="http://github.com/llimllib/personal_code/blob/master/python/permutation/permute.py#L233"&gt;here&lt;/a&gt;.

&lt;p&gt;&lt;h2&gt;Odds and Ends&lt;/h2&gt;

&lt;p&gt;Well, that's it, just wanted to post some fun pictures of permutations, I
hope you enjoyed it. The code I used to generate the pictures is derived from
Aldo Cortesi's wonderful &lt;a
href="http://github.com/cortesi/sortvis"&gt;sortvis&lt;/a&gt;, and all my modifications to
it are &lt;a
href="http://github.com/llimllib/personal_code/tree/master/python/permvis"&gt;available
on github&lt;/a&gt; as well.

&lt;p&gt;If you want bonus points, I never got around to implementing Knuth's
algorithm E (it's given towards the end of &lt;a
href="http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz"&gt;this&lt;/a&gt;), and
I'd love for somebody else to do my work for me. If you're tough enough, that
is.
</summary>
		<content type="html">&lt;p&gt;At some point a few years ago, I got interested in permutation algorithms and
implemented a few that were in Knuth as well as gathered some that were
floating around the internet. I never did anything with them, until I saw Aldo
Cortesi's excellent &lt;a
href="http://corte.si/posts/code/visualisingsorting/index.html"&gt;sorting
visualizations&lt;/a&gt; which reminded me of &lt;a
href="http://img.skitch.com/20100429-muthj97xmh8a34dnwnqkc64d6e.jpg"&gt;a figure
from Knuth&lt;/a&gt;, and inspired me to create some visualizations of my own using
Aldo's code.

&lt;p&gt;&lt;h2&gt;Lexicographic Permutations&lt;/h2&gt;

&lt;p&gt;Informally, the permutations of a set are all possible orderings of its
members. The permutations of the set &lt;i&gt;{1,2,3}&lt;/i&gt;, are: 

&lt;p&gt;&lt;code&gt;[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1]&lt;/code&gt;

&lt;p&gt;This particular ordering of permutations is in &lt;i&gt;lexicographic order&lt;/i&gt;;
it's listed in the same order as it would be in the dictionary. There are many
well-known algorithms for generating permutations in lexicographic order. &lt;a
href="http://github.com/llimllib/personal_code/blob/master/python/permutation/permute.py#L5"&gt;Here&lt;/a&gt;
is my version of one such algorithm; &lt;a
href="http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz"&gt;go read Knuth&lt;/a&gt;
if you're at all interested in learning more.

&lt;p&gt;Here's what a lexicographic permutation of four elements looks like:

&lt;p&gt;&lt;img src="http://billmill.org/static/perm1.png"&gt;

&lt;p&gt;It's easy to see that each element gets its turn at the top of the list, and
that each time a new element goes to the top the remainder of the list is
sorted.

&lt;p&gt;&lt;h2&gt;Single-transposition Permutations&lt;/h2&gt;

&lt;p&gt;It is an interesting and non-obvious fact that there's a way to permute any
given set by only switching the positions of one pair of elements per iteration.
This permutation is deeply related to the &lt;a
href="http://en.wikipedia.org/wiki/Gray_code"&gt;Gray code&lt;/a&gt;, which if you
haven't heard of, I highly recommend you go read about. The Knuth &lt;a
href="http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz"&gt;paper&lt;/a&gt; I
mentioned aleady has a superb bit on the Gray code.

&lt;p&gt;&lt;img src="http://billmill.org/static/perm4.png"&gt;

&lt;p&gt;This image demonstrates clearly that at each step, there is exactly one
crossing. My implementation of this algorithm is &lt;a
href="http://github.com/llimllib/personal_code/blob/master/python/permutation/permute.py#L201"&gt;also
on github.&lt;/a&gt;

&lt;p&gt;&lt;h2&gt;CLP Permutation&lt;/h2&gt;

&lt;p&gt;I know very little about this algorithm, except that I got it from &lt;a
href="http://mail.python.org/pipermail/python-list/2002-November/170393.html"&gt;a message
to comp.lang.python&lt;/a&gt; where it's attributed to Alex Martelli, Duncan Smith,
and somebody named Anton (Anton Vredegoor?). Despite the crazy number of
switches, and the fact that it reorders the list it's passed, it's actually
crazy fast.

&lt;p&gt;&lt;img src="http://billmill.org/static/clp_perm.png"&gt;

&lt;p&gt;I'd love to hear from anyone with more info on this algorithm; my slightly
modified version is &lt;a
href="http://github.com/llimllib/personal_code/blob/master/python/permutation/permute.py#L233"&gt;here&lt;/a&gt;.

&lt;p&gt;&lt;h2&gt;Odds and Ends&lt;/h2&gt;

&lt;p&gt;Well, that's it, just wanted to post some fun pictures of permutations, I
hope you enjoyed it. The code I used to generate the pictures is derived from
Aldo Cortesi's wonderful &lt;a
href="http://github.com/cortesi/sortvis"&gt;sortvis&lt;/a&gt;, and all my modifications to
it are &lt;a
href="http://github.com/llimllib/personal_code/tree/master/python/permvis"&gt;available
on github&lt;/a&gt; as well.

&lt;p&gt;If you want bonus points, I never got around to implementing Knuth's
algorithm E (it's given towards the end of &lt;a
href="http://www-cs-faculty.stanford.edu/~knuth/fasc2b.ps.gz"&gt;this&lt;/a&gt;), and
I'd love for somebody else to do my work for me. If you're tough enough, that
is.
</content>
	</entry>
	<entry>
		<title>Evaluating A Few Bracket Picking Models</title>
		<link href="http://billmill.org/bracket_randomizer_success.html" />	
		<id>http://billmill.org/bracket_randomizer_success.html</id>
		<updated>2010-03-24T01:00:00Z</updated>
		<summary type="html">&lt;p&gt;Since I made the &lt;a href="http://billmill.org/ncaa_randomizer.html"&gt;bracket
randomizer&lt;/a&gt; (please go read that if you haven't, or this won't make any sense
to you) I've been wondering about its performance.&lt;/p&gt;

&lt;p&gt;Included in the bracket randomizer are four models used to pick which team
will win a game; one is quite simple and the other three are variations on
a slightly more complicated scheme:

&lt;p&gt;&lt;ul&gt;&lt;li&gt;The Pomeroy Strict Model: simply choose the higher ranked team
&lt;li&gt;The Pomeroy Random Model, &lt;em&gt;n&lt;/em&gt; reps: compute the win probability
of each team in a game. Choose a random number &lt;em&gt;n&lt;/em&gt; times; if it's less than the
underdog's win probability each of those times, the underdog wins. Else the
favorite does. &lt;em&gt;n&lt;/em&gt; is 1 for "lots of randomness", 2 for "some
randomness", and 3 for "not much randomness".&lt;/ul&gt;

&lt;p&gt;For fun, I hacked up a couple other possible models to compare to the ones
above:

&lt;p&gt;&lt;ul&gt;&lt;li&gt;The Seed Model: choose the better-seeded team until the final four,
then pick randomly
&lt;li&gt;The Pure Random Model: always choose randomly&lt;/ul&gt;
&lt;p&gt;To check how well the models predict, I ran each one 10,000 times and
calculated how many games it predicted correctly:
&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="/static/jquery.flot.js"&gt;&lt;/script&gt; 

&lt;script&gt; 
$(function () {
    var options = {
        legend: {position: 'nw', backgroundOpacity: 0},
        yaxis: {max: 5000},
        series: {
            lines: { show: true },
        }}
    $.plot($("#ncorrect"), [{label: 'Pomeroy Random Model 1 reps', data: [[16, 2], [17, 1], [18, 4], [19, 21], [20, 43], [21, 83], [22, 163], [23, 297], [24, 526], [25, 739], [26, 932], [27, 1125], [28, 1247], [29, 1208], [30, 1076], [31, 859], [32, 648], [33, 488], [34, 273], [35, 145], [36, 66], [37, 33], [38, 12], [39, 7], [40, 2]]},{label: 'Pomeroy Random Model 2 reps', data: [[23, 4], [24, 10], [25, 52], [26, 121], [27, 278], [28, 544], [29, 949], [30, 1365], [31, 1646], [32, 1713], [33, 1453], [34, 951], [35, 539], [36, 243], [37, 99], [38, 24], [39, 8], [40, 1]]},{label: 'Pomeroy Random Model 3 reps', data: [[25, 2], [26, 3], [27, 25], [28, 98], [29, 307], [30, 791], [31, 1540], [32, 2366], [33, 2666], [34, 1364], [35, 622], [36, 164], [37, 49], [38, 3]]},{label: 'Pomeroy Random Model 4 reps', data: [[26, 1], [27, 1], [28, 11], [29, 50], [30, 260], [31, 943], [32, 2190], [33, 4655], [34, 1376], [35, 430], [36, 69], [37, 12], [38, 2]]},{label: 'Pomeroy Strict Model', data: [[33, 5000], [32.999899999999997, 0]]},{label: 'Pure Random Model', data: [[5, 1], [6, 1], [7, 1], [8, 5], [9, 9], [10, 34], [11, 56], [12, 135], [13, 196], [14, 331], [15, 461], [16, 621], [17, 802], [18, 918], [19, 983], [20, 987], [21, 969], [22, 886], [23, 729], [24, 591], [25, 458], [26, 331], [27, 212], [28, 127], [29, 77], [30, 37], [31, 20], [32, 14], [33, 5], [34, 3]]},{label: 'Seed Model', data: [[30, 10000], [29.9999, 0]]}], options);
    $.plot($("#actual"), [{label: 'Pomeroy Random Model 1 reps', data: [[18, 2], [19, 2], [20, 1], [21, 6], [22, 17], [23, 24], [24, 47], [25, 76], [26, 117], [27, 180], [28, 287], [29, 391], [30, 475], [31, 534], [32, 716], [33, 780], [34, 859], [35, 838], [36, 823], [37, 794], [38, 693], [39, 570], [40, 451], [41, 415], [42, 319], [43, 194], [44, 169], [45, 107], [46, 42], [47, 25], [48, 23], [49, 9], [50, 10], [52, 3], [53, 1]]},{label: 'Pomeroy Random Model 2 reps', data: [[27, 4], [28, 6], [29, 17], [30, 27], [31, 57], [32, 112], [33, 194], [34, 303], [35, 414], [36, 648], [37, 848], [38, 1017], [39, 1100], [40, 1126], [41, 1126], [42, 966], [43, 717], [44, 537], [45, 369], [46, 200], [47, 107], [48, 58], [49, 32], [50, 8], [51, 4], [52, 3]]},{label: 'Pomeroy Random Model 3 reps', data: [[30, 2], [31, 1], [32, 6], [33, 18], [34, 45], [35, 103], [36, 222], [37, 396], [38, 669], [39, 1065], [40, 1431], [41, 1457], [42, 2152], [43, 1006], [44, 707], [45, 450], [46, 156], [47, 74], [48, 33], [49, 6], [50, 1]]},{label: 'Pomeroy Random Model 4 reps', data: [[32, 1], [33, 1], [34, 3], [35, 9], [36, 39], [37, 104], [38, 260], [39, 724], [40, 1148], [41, 1330], [42, 4370], [43, 974], [44, 568], [45, 359], [46, 65], [47, 35], [48, 7], [49, 3]]},{label: 'Pomeroy Strict Model', data: [[42, 5000], [41.999899999999997, 0]]},{label: 'Pure Random Model', data: [[5, 1], [7, 1], [8, 3], [9, 7], [10, 10], [11, 25], [12, 53], [13, 81], [14, 125], [15, 187], [16, 268], [17, 317], [18, 420], [19, 544], [20, 603], [21, 664], [22, 730], [23, 720], [24, 734], [25, 705], [26, 651], [27, 599], [28, 543], [29, 458], [30, 383], [31, 319], [32, 244], [33, 193], [34, 124], [35, 102], [36, 72], [37, 51], [38, 21], [39, 13], [40, 14], [41, 7], [42, 6], [43, 2]]},{label: 'Seed Model', data: [[38, 10000], [37.999899999999997, 0]]}], options);
    var possible_data = [{label: 'Pomeroy Random Model 1 reps', data: [[18, 1], [19, 1], [21, 1], [22, 3], [23, 2], [24, 1], [25, 4], [26, 6], [27, 4], [28, 6], [29, 6], [30, 9], [31, 14], [32, 18], [33, 28], [34, 15], [35, 23], [36, 27], [37, 28], [38, 30], [39, 25], [40, 35], [41, 49], [42, 46], [43, 49], [44, 44], [45, 40], [46, 46], [47, 56], [48, 48], [49, 53], [50, 69], [51, 55], [52, 69], [53, 57], [54, 54], [55, 62], [56, 69], [57, 75], [58, 62], [59, 69], [60, 71], [61, 86], [62, 78], [63, 66], [64, 76], [65, 84], [66, 90], [67, 86], [68, 83], [69, 85], [70, 91], [71, 85], [72, 87], [73, 74], [74, 82], [75, 79], [76, 87], [77, 97], [78, 94], [79, 64], [80, 95], [81, 81], [82, 80], [83, 80], [84, 92], [85, 81], [86, 74], [87, 86], [88, 112], [89, 90], [90, 79], [91, 80], [92, 65], [93, 86], [94, 77], [95, 65], [96, 91], [97, 85], [98, 91], [99, 82], [100, 92], [101, 85], [102, 107], [103, 84], [104, 86], [105, 99], [106, 86], [107, 94], [108, 100], [109, 91], [110, 112], [111, 90], [112, 88], [113, 105], [114, 94], [115, 100], [116, 101], [117, 110], [118, 92], [119, 113], [120, 77], [121, 95], [122, 102], [123, 99], [124, 95], [125, 101], [126, 94], [127, 91], [128, 91], [129, 89], [130, 83], [131, 106], [132, 87], [133, 90], [134, 116], [135, 79], [136, 93], [137, 118], [138, 93], [139, 97], [140, 84], [141, 101], [142, 88], [143, 60], [144, 95], [145, 83], [146, 85], [147, 62], [148, 74], [149, 71], [150, 74], [151, 50], [152, 64], [153, 58], [154, 56], [155, 43], [156, 43], [157, 44], [158, 36], [159, 30], [160, 41], [161, 18], [162, 21], [163, 22], [164, 21], [165, 16], [166, 13], [167, 11], [168, 9], [169, 12], [170, 2], [171, 3], [172, 2], [173, 1], [174, 3], [176, 1], [177, 2]]},{label: 'Pomeroy Random Model 2 reps', data: [[34, 1], [36, 1], [38, 1], [40, 2], [41, 1], [42, 1], [43, 3], [44, 1], [46, 8], [47, 5], [48, 2], [49, 7], [50, 8], [51, 4], [52, 13], [53, 15], [54, 11], [55, 12], [56, 12], [57, 14], [58, 20], [59, 26], [60, 23], [61, 25], [62, 31], [63, 34], [64, 32], [65, 31], [66, 32], [67, 37], [68, 46], [69, 53], [70, 47], [71, 50], [72, 63], [73, 76], [74, 73], [75, 56], [76, 69], [77, 56], [78, 66], [79, 74], [80, 59], [81, 62], [82, 71], [83, 66], [84, 71], [85, 79], [86, 78], [87, 74], [88, 94], [89, 86], [90, 85], [91, 71], [92, 89], [93, 114], [94, 95], [95, 92], [96, 101], [97, 74], [98, 87], [99, 92], [100, 81], [101, 82], [102, 95], [103, 79], [104, 92], [105, 94], [106, 95], [107, 90], [108, 88], [109, 108], [110, 89], [111, 92], [112, 103], [113, 115], [114, 146], [115, 145], [116, 125], [117, 181], [118, 170], [119, 163], [120, 183], [121, 199], [122, 198], [123, 192], [124, 176], [125, 218], [126, 214], [127, 170], [128, 193], [129, 162], [130, 143], [131, 169], [132, 180], [133, 183], [134, 120], [135, 123], [136, 131], [137, 129], [138, 153], [139, 118], [140, 124], [141, 110], [142, 89], [143, 83], [144, 81], [145, 88], [146, 86], [147, 72], [148, 71], [149, 82], [150, 77], [151, 81], [152, 61], [153, 57], [154, 60], [155, 44], [156, 64], [157, 39], [158, 38], [159, 46], [160, 29], [161, 19], [162, 22], [163, 27], [164, 23], [165, 20], [166, 8], [167, 10], [168, 6], [169, 6], [170, 3], [171, 3], [172, 1], [173, 1]]},{label: 'Pomeroy Random Model 3 reps', data: [[50, 2], [52, 1], [54, 1], [56, 1], [57, 2], [58, 6], [59, 2], [60, 6], [61, 3], [62, 3], [63, 7], [64, 8], [65, 6], [66, 11], [67, 15], [68, 16], [69, 22], [70, 22], [71, 17], [72, 29], [73, 14], [74, 32], [75, 46], [76, 47], [77, 52], [78, 64], [79, 47], [80, 28], [81, 38], [82, 23], [83, 31], [84, 43], [85, 33], [86, 32], [87, 40], [88, 65], [89, 48], [90, 68], [91, 65], [92, 82], [93, 89], [94, 133], [95, 61], [96, 51], [97, 52], [98, 42], [99, 30], [100, 44], [101, 36], [102, 43], [103, 39], [104, 32], [105, 38], [106, 51], [107, 34], [108, 44], [109, 50], [110, 39], [111, 78], [112, 90], [113, 77], [114, 92], [115, 89], [116, 120], [117, 172], [118, 244], [119, 214], [120, 289], [121, 282], [122, 396], [123, 469], [124, 501], [125, 547], [126, 873], [127, 386], [128, 307], [129, 259], [130, 239], [131, 195], [132, 236], [133, 160], [134, 172], [135, 143], [136, 114], [137, 137], [138, 186], [139, 86], [140, 86], [141, 71], [142, 81], [143, 54], [144, 52], [145, 44], [146, 38], [147, 33], [148, 47], [149, 42], [150, 79], [151, 31], [152, 22], [153, 21], [154, 26], [155, 21], [156, 20], [157, 16], [158, 11], [159, 6], [160, 9], [161, 11], [162, 12], [163, 7], [164, 7], [165, 4], [166, 4], [167, 2], [168, 1], [169, 1], [171, 1], [172, 1]]},{label: 'Pomeroy Random Model 4 reps', data: [[61, 1], [63, 1], [64, 1], [66, 1], [69, 2], [70, 6], [71, 1], [72, 4], [73, 5], [74, 9], [75, 11], [76, 18], [77, 23], [78, 73], [79, 15], [80, 5], [81, 2], [82, 4], [83, 3], [84, 8], [85, 5], [86, 11], [87, 6], [88, 14], [89, 10], [90, 40], [91, 25], [92, 37], [93, 57], [94, 171], [95, 48], [96, 15], [97, 18], [98, 15], [99, 10], [100, 12], [101, 9], [102, 12], [103, 5], [104, 3], [105, 8], [106, 17], [107, 5], [108, 9], [109, 15], [110, 17], [111, 24], [112, 56], [113, 25], [114, 42], [115, 46], [116, 54], [117, 82], [118, 248], [119, 130], [120, 267], [121, 156], [122, 384], [123, 513], [124, 630], [125, 860], [126, 2984], [127, 617], [128, 271], [129, 292], [130, 157], [131, 136], [132, 230], [133, 80], [134, 154], [135, 66], [136, 53], [137, 75], [138, 217], [139, 40], [140, 29], [141, 42], [142, 47], [143, 11], [144, 17], [145, 10], [146, 13], [147, 9], [148, 18], [149, 15], [150, 63], [151, 14], [152, 10], [153, 3], [154, 5], [155, 2], [156, 2], [157, 2], [158, 4], [159, 1], [162, 4], [163, 2], [167, 1]]},{label: 'Pomeroy Strict Model', data: [[126, 10000], [125.9999, 0]]},{label: 'Pure Random Model', data: [[5, 1], [7, 1], [8, 3], [9, 5], [10, 9], [11, 16], [12, 40], [13, 44], [14, 55], [15, 70], [16, 92], [17, 102], [18, 125], [19, 148], [20, 148], [21, 151], [22, 168], [23, 171], [24, 176], [25, 185], [26, 191], [27, 173], [28, 191], [29, 176], [30, 176], [31, 187], [32, 176], [33, 174], [34, 169], [35, 181], [36, 169], [37, 203], [38, 149], [39, 150], [40, 138], [41, 121], [42, 139], [43, 118], [44, 129], [45, 116], [46, 118], [47, 106], [48, 126], [49, 114], [50, 113], [51, 112], [52, 113], [53, 96], [54, 73], [55, 85], [56, 74], [57, 88], [58, 77], [59, 94], [60, 84], [61, 76], [62, 67], [63, 74], [64, 60], [65, 54], [66, 56], [67, 67], [68, 51], [69, 40], [70, 57], [71, 39], [72, 42], [73, 51], [74, 33], [75, 46], [76, 64], [77, 59], [78, 51], [79, 66], [80, 63], [81, 63], [82, 68], [83, 74], [84, 60], [85, 69], [86, 81], [87, 66], [88, 57], [89, 71], [90, 80], [91, 77], [92, 64], [93, 53], [94, 60], [95, 53], [96, 52], [97, 47], [98, 63], [99, 57], [100, 45], [101, 56], [102, 52], [103, 53], [104, 61], [105, 46], [106, 51], [107, 42], [108, 47], [109, 27], [110, 30], [111, 34], [112, 24], [113, 37], [114, 31], [115, 34], [116, 37], [117, 35], [118, 16], [119, 23], [120, 33], [121, 26], [122, 29], [123, 23], [124, 33], [125, 29], [126, 28], [127, 18], [128, 27], [129, 13], [130, 20], [131, 18], [132, 22], [133, 15], [134, 13], [135, 9], [136, 8], [137, 18], [138, 7], [139, 9], [140, 11], [141, 8], [142, 6], [143, 7], [144, 3], [145, 9], [146, 3], [147, 7], [148, 7], [149, 2], [150, 2], [151, 3], [152, 3], [153, 3], [154, 4], [155, 1], [157, 1], [164, 1]]},{label: 'Seed Model', data: [[102, 2574], [134, 2486], [150, 4940]]}]
    $.plot($("#possible"), possible_data, options);
    options.xaxis = {min:75, max:150}
    options.yaxis = {max:1000}
    $.plot($("#possiblezoom"), possible_data, options);
    options.xaxis = {min:158}
    options.yaxis = {max:10}
    options.legend = {position: 'ne', backgroundOpacity: 0},
    $.plot($("#possiblezoom2"), possible_data, options);
});
&lt;/script&gt;
&lt;div id="ncorrect" style="width:600px;height:400px"&gt;&lt;/div&gt; 
&lt;p&gt;We can see immediately that, of 38 games so far, the higher-seeded team
has won 30 of them and the higher Pomeroy-ranked team has won 33. It should
also come as no surprise that the random model most frequently predicted
half the games right.
&lt;p&gt;As the value of &lt;em&gt;n&lt;/em&gt; in the Pomeroy random model increases,
the curve moves from halfway in between the random and the Pomeroy
strict model, with a large spread of possibilities, to a closer and closer
approximation of the Pomeroy strict model.
&lt;p&gt;In most bracket pools, the number of games doesn't matter as much as the number
of points scored. It should not surprise us that this graph doesn't look much
different from the graph of total games predicted accurately.
&lt;div id="actual" style="width:600px;height:400px"&gt;&lt;/div&gt;
&lt;p&gt;The most important statistic for your bracket pool is the number of
points you can still win; with Kansas (a #1 seed) out already, many people
have lost their predicted champions. This creates an immediately
obvious pattern in the possible remaining points for the seed model.
&lt;div id="possible" style="width:600px;height:400px"&gt;&lt;/div&gt;
&lt;p&gt;Since the seed model always picks all four #1 seeds to the final
four, then chooses randomly among them, half the time it picks Kansas
to lose its semifinal, and has a pretty darn good total points
remaining score. Half of the remaining time, it chooses Kansas to
win the national championship and has a poor one; otherwise
Kansas loses in the championship and the remaining score is in
the middle. This explains the seemingly strange shape at the top
of the graph.
&lt;p&gt;Another thing the whole graph shows us is the true awfulness of
the pure random model; its most common result leaves your bracket with
an underwhelming 37 points remaining.
&lt;p&gt;Let's zoom in and check out what's going on down below the seed model.
&lt;div id="possiblezoom" style="width:600px;height:400px"&gt;&lt;/div&gt; 
&lt;p&gt;Again, as &lt;em&gt;n&lt;/em&gt; increases in the Pomeroy random model,
it approximates the strict Pomeroy model more closely. What's interesting
to me, though, is between the two and the three repetition models; the two
repetition model has a much greater spread than the three, and many
fewer cases right near the Pomeroy line. I don't have a good theory for
why this is, so if you do, please let me know.
&lt;p&gt;In my bracket pools, anybody with a possible score over 100 is doing well,
and anybody with a possible score of 140 or higher is kicking serious
butt. If you picked your bracket using the Pomeroy strict 2 rep model
(like I did, incidentally), you have roughly a 16.3% chance of having
&gt;=140 points remaining, and a 71.4% chance of having &gt;=100 points
remaining.
&lt;p&gt;Unfortunately, I don't have good data to know what is a good "points
remaining" score. If you do have access to such data, please let me know.
&lt;p&gt;But what if you want more? What if you want not just to win your office
pool, but to beat everybody in the bracket? Well then, you'll want to zoom
in on the very high end of the distribution.
&lt;div id="possiblezoom2" style="width:600px;height:400px"&gt;&lt;/div&gt; 
&lt;p&gt;The Pomeroy model with the most randomness has the very
highest scores, with two brackets having a whopping 177 possible points 
remaining. It's also apparent that the less random a model is, the less
highly unlikely events it creates, and the less likely it is to produce
a world-beating near-perfect bracket.
&lt;p&gt;If you've got an idea for a different model you'd like to try out,
or you just want to show me where the bugs in my code are, you can
go &lt;a
href="http://github.com/llimllib/ncaa-bracket-randomizer/blob/master/analyze.py"&gt;check
it out&lt;/a&gt; at github.
</summary>
		<content type="html">&lt;p&gt;Since I made the &lt;a href="http://billmill.org/ncaa_randomizer.html"&gt;bracket
randomizer&lt;/a&gt; (please go read that if you haven't, or this won't make any sense
to you) I've been wondering about its performance.&lt;/p&gt;

&lt;p&gt;Included in the bracket randomizer are four models used to pick which team
will win a game; one is quite simple and the other three are variations on
a slightly more complicated scheme:

&lt;p&gt;&lt;ul&gt;&lt;li&gt;The Pomeroy Strict Model: simply choose the higher ranked team
&lt;li&gt;The Pomeroy Random Model, &lt;em&gt;n&lt;/em&gt; reps: compute the win probability
of each team in a game. Choose a random number &lt;em&gt;n&lt;/em&gt; times; if it's less than the
underdog's win probability each of those times, the underdog wins. Else the
favorite does. &lt;em&gt;n&lt;/em&gt; is 1 for "lots of randomness", 2 for "some
randomness", and 3 for "not much randomness".&lt;/ul&gt;

&lt;p&gt;For fun, I hacked up a couple other possible models to compare to the ones
above:

&lt;p&gt;&lt;ul&gt;&lt;li&gt;The Seed Model: choose the better-seeded team until the final four,
then pick randomly
&lt;li&gt;The Pure Random Model: always choose randomly&lt;/ul&gt;
&lt;p&gt;To check how well the models predict, I ran each one 10,000 times and
calculated how many games it predicted correctly:
&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;&lt;/script&gt;
&lt;script src="/static/jquery.flot.js"&gt;&lt;/script&gt; 

&lt;script&gt; 
$(function () {
    var options = {
        legend: {position: 'nw', backgroundOpacity: 0},
        yaxis: {max: 5000},
        series: {
            lines: { show: true },
        }}
    $.plot($("#ncorrect"), [{label: 'Pomeroy Random Model 1 reps', data: [[16, 2], [17, 1], [18, 4], [19, 21], [20, 43], [21, 83], [22, 163], [23, 297], [24, 526], [25, 739], [26, 932], [27, 1125], [28, 1247], [29, 1208], [30, 1076], [31, 859], [32, 648], [33, 488], [34, 273], [35, 145], [36, 66], [37, 33], [38, 12], [39, 7], [40, 2]]},{label: 'Pomeroy Random Model 2 reps', data: [[23, 4], [24, 10], [25, 52], [26, 121], [27, 278], [28, 544], [29, 949], [30, 1365], [31, 1646], [32, 1713], [33, 1453], [34, 951], [35, 539], [36, 243], [37, 99], [38, 24], [39, 8], [40, 1]]},{label: 'Pomeroy Random Model 3 reps', data: [[25, 2], [26, 3], [27, 25], [28, 98], [29, 307], [30, 791], [31, 1540], [32, 2366], [33, 2666], [34, 1364], [35, 622], [36, 164], [37, 49], [38, 3]]},{label: 'Pomeroy Random Model 4 reps', data: [[26, 1], [27, 1], [28, 11], [29, 50], [30, 260], [31, 943], [32, 2190], [33, 4655], [34, 1376], [35, 430], [36, 69], [37, 12], [38, 2]]},{label: 'Pomeroy Strict Model', data: [[33, 5000], [32.999899999999997, 0]]},{label: 'Pure Random Model', data: [[5, 1], [6, 1], [7, 1], [8, 5], [9, 9], [10, 34], [11, 56], [12, 135], [13, 196], [14, 331], [15, 461], [16, 621], [17, 802], [18, 918], [19, 983], [20, 987], [21, 969], [22, 886], [23, 729], [24, 591], [25, 458], [26, 331], [27, 212], [28, 127], [29, 77], [30, 37], [31, 20], [32, 14], [33, 5], [34, 3]]},{label: 'Seed Model', data: [[30, 10000], [29.9999, 0]]}], options);
    $.plot($("#actual"), [{label: 'Pomeroy Random Model 1 reps', data: [[18, 2], [19, 2], [20, 1], [21, 6], [22, 17], [23, 24], [24, 47], [25, 76], [26, 117], [27, 180], [28, 287], [29, 391], [30, 475], [31, 534], [32, 716], [33, 780], [34, 859], [35, 838], [36, 823], [37, 794], [38, 693], [39, 570], [40, 451], [41, 415], [42, 319], [43, 194], [44, 169], [45, 107], [46, 42], [47, 25], [48, 23], [49, 9], [50, 10], [52, 3], [53, 1]]},{label: 'Pomeroy Random Model 2 reps', data: [[27, 4], [28, 6], [29, 17], [30, 27], [31, 57], [32, 112], [33, 194], [34, 303], [35, 414], [36, 648], [37, 848], [38, 1017], [39, 1100], [40, 1126], [41, 1126], [42, 966], [43, 717], [44, 537], [45, 369], [46, 200], [47, 107], [48, 58], [49, 32], [50, 8], [51, 4], [52, 3]]},{label: 'Pomeroy Random Model 3 reps', data: [[30, 2], [31, 1], [32, 6], [33, 18], [34, 45], [35, 103], [36, 222], [37, 396], [38, 669], [39, 1065], [40, 1431], [41, 1457], [42, 2152], [43, 1006], [44, 707], [45, 450], [46, 156], [47, 74], [48, 33], [49, 6], [50, 1]]},{label: 'Pomeroy Random Model 4 reps', data: [[32, 1], [33, 1], [34, 3], [35, 9], [36, 39], [37, 104], [38, 260], [39, 724], [40, 1148], [41, 1330], [42, 4370], [43, 974], [44, 568], [45, 359], [46, 65], [47, 35], [48, 7], [49, 3]]},{label: 'Pomeroy Strict Model', data: [[42, 5000], [41.999899999999997, 0]]},{label: 'Pure Random Model', data: [[5, 1], [7, 1], [8, 3], [9, 7], [10, 10], [11, 25], [12, 53], [13, 81], [14, 125], [15, 187], [16, 268], [17, 317], [18, 420], [19, 544], [20, 603], [21, 664], [22, 730], [23, 720], [24, 734], [25, 705], [26, 651], [27, 599], [28, 543], [29, 458], [30, 383], [31, 319], [32, 244], [33, 193], [34, 124], [35, 102], [36, 72], [37, 51], [38, 21], [39, 13], [40, 14], [41, 7], [42, 6], [43, 2]]},{label: 'Seed Model', data: [[38, 10000], [37.999899999999997, 0]]}], options);
    var possible_data = [{label: 'Pomeroy Random Model 1 reps', data: [[18, 1], [19, 1], [21, 1], [22, 3], [23, 2], [24, 1], [25, 4], [26, 6], [27, 4], [28, 6], [29, 6], [30, 9], [31, 14], [32, 18], [33, 28], [34, 15], [35, 23], [36, 27], [37, 28], [38, 30], [39, 25], [40, 35], [41, 49], [42, 46], [43, 49], [44, 44], [45, 40], [46, 46], [47, 56], [48, 48], [49, 53], [50, 69], [51, 55], [52, 69], [53, 57], [54, 54], [55, 62], [56, 69], [57, 75], [58, 62], [59, 69], [60, 71], [61, 86], [62, 78], [63, 66], [64, 76], [65, 84], [66, 90], [67, 86], [68, 83], [69, 85], [70, 91], [71, 85], [72, 87], [73, 74], [74, 82], [75, 79], [76, 87], [77, 97], [78, 94], [79, 64], [80, 95], [81, 81], [82, 80], [83, 80], [84, 92], [85, 81], [86, 74], [87, 86], [88, 112], [89, 90], [90, 79], [91, 80], [92, 65], [93, 86], [94, 77], [95, 65], [96, 91], [97, 85], [98, 91], [99, 82], [100, 92], [101, 85], [102, 107], [103, 84], [104, 86], [105, 99], [106, 86], [107, 94], [108, 100], [109, 91], [110, 112], [111, 90], [112, 88], [113, 105], [114, 94], [115, 100], [116, 101], [117, 110], [118, 92], [119, 113], [120, 77], [121, 95], [122, 102], [123, 99], [124, 95], [125, 101], [126, 94], [127, 91], [128, 91], [129, 89], [130, 83], [131, 106], [132, 87], [133, 90], [134, 116], [135, 79], [136, 93], [137, 118], [138, 93], [139, 97], [140, 84], [141, 101], [142, 88], [143, 60], [144, 95], [145, 83], [146, 85], [147, 62], [148, 74], [149, 71], [150, 74], [151, 50], [152, 64], [153, 58], [154, 56], [155, 43], [156, 43], [157, 44], [158, 36], [159, 30], [160, 41], [161, 18], [162, 21], [163, 22], [164, 21], [165, 16], [166, 13], [167, 11], [168, 9], [169, 12], [170, 2], [171, 3], [172, 2], [173, 1], [174, 3], [176, 1], [177, 2]]},{label: 'Pomeroy Random Model 2 reps', data: [[34, 1], [36, 1], [38, 1], [40, 2], [41, 1], [42, 1], [43, 3], [44, 1], [46, 8], [47, 5], [48, 2], [49, 7], [50, 8], [51, 4], [52, 13], [53, 15], [54, 11], [55, 12], [56, 12], [57, 14], [58, 20], [59, 26], [60, 23], [61, 25], [62, 31], [63, 34], [64, 32], [65, 31], [66, 32], [67, 37], [68, 46], [69, 53], [70, 47], [71, 50], [72, 63], [73, 76], [74, 73], [75, 56], [76, 69], [77, 56], [78, 66], [79, 74], [80, 59], [81, 62], [82, 71], [83, 66], [84, 71], [85, 79], [86, 78], [87, 74], [88, 94], [89, 86], [90, 85], [91, 71], [92, 89], [93, 114], [94, 95], [95, 92], [96, 101], [97, 74], [98, 87], [99, 92], [100, 81], [101, 82], [102, 95], [103, 79], [104, 92], [105, 94], [106, 95], [107, 90], [108, 88], [109, 108], [110, 89], [111, 92], [112, 103], [113, 115], [114, 146], [115, 145], [116, 125], [117, 181], [118, 170], [119, 163], [120, 183], [121, 199], [122, 198], [123, 192], [124, 176], [125, 218], [126, 214], [127, 170], [128, 193], [129, 162], [130, 143], [131, 169], [132, 180], [133, 183], [134, 120], [135, 123], [136, 131], [137, 129], [138, 153], [139, 118], [140, 124], [141, 110], [142, 89], [143, 83], [144, 81], [145, 88], [146, 86], [147, 72], [148, 71], [149, 82], [150, 77], [151, 81], [152, 61], [153, 57], [154, 60], [155, 44], [156, 64], [157, 39], [158, 38], [159, 46], [160, 29], [161, 19], [162, 22], [163, 27], [164, 23], [165, 20], [166, 8], [167, 10], [168, 6], [169, 6], [170, 3], [171, 3], [172, 1], [173, 1]]},{label: 'Pomeroy Random Model 3 reps', data: [[50, 2], [52, 1], [54, 1], [56, 1], [57, 2], [58, 6], [59, 2], [60, 6], [61, 3], [62, 3], [63, 7], [64, 8], [65, 6], [66, 11], [67, 15], [68, 16], [69, 22], [70, 22], [71, 17], [72, 29], [73, 14], [74, 32], [75, 46], [76, 47], [77, 52], [78, 64], [79, 47], [80, 28], [81, 38], [82, 23], [83, 31], [84, 43], [85, 33], [86, 32], [87, 40], [88, 65], [89, 48], [90, 68], [91, 65], [92, 82], [93, 89], [94, 133], [95, 61], [96, 51], [97, 52], [98, 42], [99, 30], [100, 44], [101, 36], [102, 43], [103, 39], [104, 32], [105, 38], [106, 51], [107, 34], [108, 44], [109, 50], [110, 39], [111, 78], [112, 90], [113, 77], [114, 92], [115, 89], [116, 120], [117, 172], [118, 244], [119, 214], [120, 289], [121, 282], [122, 396], [123, 469], [124, 501], [125, 547], [126, 873], [127, 386], [128, 307], [129, 259], [130, 239], [131, 195], [132, 236], [133, 160], [134, 172], [135, 143], [136, 114], [137, 137], [138, 186], [139, 86], [140, 86], [141, 71], [142, 81], [143, 54], [144, 52], [145, 44], [146, 38], [147, 33], [148, 47], [149, 42], [150, 79], [151, 31], [152, 22], [153, 21], [154, 26], [155, 21], [156, 20], [157, 16], [158, 11], [159, 6], [160, 9], [161, 11], [162, 12], [163, 7], [164, 7], [165, 4], [166, 4], [167, 2], [168, 1], [169, 1], [171, 1], [172, 1]]},{label: 'Pomeroy Random Model 4 reps', data: [[61, 1], [63, 1], [64, 1], [66, 1], [69, 2], [70, 6], [71, 1], [72, 4], [73, 5], [74, 9], [75, 11], [76, 18], [77, 23], [78, 73], [79, 15], [80, 5], [81, 2], [82, 4], [83, 3], [84, 8], [85, 5], [86, 11], [87, 6], [88, 14], [89, 10], [90, 40], [91, 25], [92, 37], [93, 57], [94, 171], [95, 48], [96, 15], [97, 18], [98, 15], [99, 10], [100, 12], [101, 9], [102, 12], [103, 5], [104, 3], [105, 8], [106, 17], [107, 5], [108, 9], [109, 15], [110, 17], [111, 24], [112, 56], [113, 25], [114, 42], [115, 46], [116, 54], [117, 82], [118, 248], [119, 130], [120, 267], [121, 156], [122, 384], [123, 513], [124, 630], [125, 860], [126, 2984], [127, 617], [128, 271], [129, 292], [130, 157], [131, 136], [132, 230], [133, 80], [134, 154], [135, 66], [136, 53], [137, 75], [138, 217], [139, 40], [140, 29], [141, 42], [142, 47], [143, 11], [144, 17], [145, 10], [146, 13], [147, 9], [148, 18], [149, 15], [150, 63], [151, 14], [152, 10], [153, 3], [154, 5], [155, 2], [156, 2], [157, 2], [158, 4], [159, 1], [162, 4], [163, 2], [167, 1]]},{label: 'Pomeroy Strict Model', data: [[126, 10000], [125.9999, 0]]},{label: 'Pure Random Model', data: [[5, 1], [7, 1], [8, 3], [9, 5], [10, 9], [11, 16], [12, 40], [13, 44], [14, 55], [15, 70], [16, 92], [17, 102], [18, 125], [19, 148], [20, 148], [21, 151], [22, 168], [23, 171], [24, 176], [25, 185], [26, 191], [27, 173], [28, 191], [29, 176], [30, 176], [31, 187], [32, 176], [33, 174], [34, 169], [35, 181], [36, 169], [37, 203], [38, 149], [39, 150], [40, 138], [41, 121], [42, 139], [43, 118], [44, 129], [45, 116], [46, 118], [47, 106], [48, 126], [49, 114], [50, 113], [51, 112], [52, 113], [53, 96], [54, 73], [55, 85], [56, 74], [57, 88], [58, 77], [59, 94], [60, 84], [61, 76], [62, 67], [63, 74], [64, 60], [65, 54], [66, 56], [67, 67], [68, 51], [69, 40], [70, 57], [71, 39], [72, 42], [73, 51], [74, 33], [75, 46], [76, 64], [77, 59], [78, 51], [79, 66], [80, 63], [81, 63], [82, 68], [83, 74], [84, 60], [85, 69], [86, 81], [87, 66], [88, 57], [89, 71], [90, 80], [91, 77], [92, 64], [93, 53], [94, 60], [95, 53], [96, 52], [97, 47], [98, 63], [99, 57], [100, 45], [101, 56], [102, 52], [103, 53], [104, 61], [105, 46], [106, 51], [107, 42], [108, 47], [109, 27], [110, 30], [111, 34], [112, 24], [113, 37], [114, 31], [115, 34], [116, 37], [117, 35], [118, 16], [119, 23], [120, 33], [121, 26], [122, 29], [123, 23], [124, 33], [125, 29], [126, 28], [127, 18], [128, 27], [129, 13], [130, 20], [131, 18], [132, 22], [133, 15], [134, 13], [135, 9], [136, 8], [137, 18], [138, 7], [139, 9], [140, 11], [141, 8], [142, 6], [143, 7], [144, 3], [145, 9], [146, 3], [147, 7], [148, 7], [149, 2], [150, 2], [151, 3], [152, 3], [153, 3], [154, 4], [155, 1], [157, 1], [164, 1]]},{label: 'Seed Model', data: [[102, 2574], [134, 2486], [150, 4940]]}]
    $.plot($("#possible"), possible_data, options);
    options.xaxis = {min:75, max:150}
    options.yaxis = {max:1000}
    $.plot($("#possiblezoom"), possible_data, options);
    options.xaxis = {min:158}
    options.yaxis = {max:10}
    options.legend = {position: 'ne', backgroundOpacity: 0},
    $.plot($("#possiblezoom2"), possible_data, options);
});
&lt;/script&gt;
&lt;div id="ncorrect" style="width:600px;height:400px"&gt;&lt;/div&gt; 
&lt;p&gt;We can see immediately that, of 38 games so far, the higher-seeded team
has won 30 of them and the higher Pomeroy-ranked team has won 33. It should
also come as no surprise that the random model most frequently predicted
half the games right.
&lt;p&gt;As the value of &lt;em&gt;n&lt;/em&gt; in the Pomeroy random model increases,
the curve moves from halfway in between the random and the Pomeroy
strict model, with a large spread of possibilities, to a closer and closer
approximation of the Pomeroy strict model.
&lt;p&gt;In most bracket pools, the number of games doesn't matter as much as the number
of points scored. It should not surprise us that this graph doesn't look much
different from the graph of total games predicted accurately.
&lt;div id="actual" style="width:600px;height:400px"&gt;&lt;/div&gt;
&lt;p&gt;The most important statistic for your bracket pool is the number of
points you can still win; with Kansas (a #1 seed) out already, many people
have lost their predicted champions. This creates an immediately
obvious pattern in the possible remaining points for the seed model.
&lt;div id="possible" style="width:600px;height:400px"&gt;&lt;/div&gt;
&lt;p&gt;Since the seed model always picks all four #1 seeds to the final
four, then chooses randomly among them, half the time it picks Kansas
to lose its semifinal, and has a pretty darn good total points
remaining score. Half of the remaining time, it chooses Kansas to
win the national championship and has a poor one; otherwise
Kansas loses in the championship and the remaining score is in
the middle. This explains the seemingly strange shape at the top
of the graph.
&lt;p&gt;Another thing the whole graph shows us is the true awfulness of
the pure random model; its most common result leaves your bracket with
an underwhelming 37 points remaining.
&lt;p&gt;Let's zoom in and check out what's going on down below the seed model.
&lt;div id="possiblezoom" style="width:600px;height:400px"&gt;&lt;/div&gt; 
&lt;p&gt;Again, as &lt;em&gt;n&lt;/em&gt; increases in the Pomeroy random model,
it approximates the strict Pomeroy model more closely. What's interesting
to me, though, is between the two and the three repetition models; the two
repetition model has a much greater spread than the three, and many
fewer cases right near the Pomeroy line. I don't have a good theory for
why this is, so if you do, please let me know.
&lt;p&gt;In my bracket pools, anybody with a possible score over 100 is doing well,
and anybody with a possible score of 140 or higher is kicking serious
butt. If you picked your bracket using the Pomeroy strict 2 rep model
(like I did, incidentally), you have roughly a 16.3% chance of having
&gt;=140 points remaining, and a 71.4% chance of having &gt;=100 points
remaining.
&lt;p&gt;Unfortunately, I don't have good data to know what is a good "points
remaining" score. If you do have access to such data, please let me know.
&lt;p&gt;But what if you want more? What if you want not just to win your office
pool, but to beat everybody in the bracket? Well then, you'll want to zoom
in on the very high end of the distribution.
&lt;div id="possiblezoom2" style="width:600px;height:400px"&gt;&lt;/div&gt; 
&lt;p&gt;The Pomeroy model with the most randomness has the very
highest scores, with two brackets having a whopping 177 possible points 
remaining. It's also apparent that the less random a model is, the less
highly unlikely events it creates, and the less likely it is to produce
a world-beating near-perfect bracket.
&lt;p&gt;If you've got an idea for a different model you'd like to try out,
or you just want to show me where the bugs in my code are, you can
go &lt;a
href="http://github.com/llimllib/ncaa-bracket-randomizer/blob/master/analyze.py"&gt;check
it out&lt;/a&gt; at github.
</content>
	</entry>
	<entry>
		<title>The Bill Mill NCAA Bracket Randomizer, 2010 edition</title>
		<link href="http://billmill.org/ncaa_randomizer_2010.html" />	
		<id>http://billmill.org/ncaa_randomizer_2010.html</id>
		<updated>2010-03-14T20:15:00Z</updated>
		<summary type="html">&lt;p&gt;I've updated my &lt;a href="http://billmill.org/ncaa_randomizer.html"&gt;NCAA bracket
randomizer&lt;/a&gt; for the 2010 field; check it out
&lt;a href="http://billmill.org/static/ncaa-bracket-randomizer/out.html"&gt;here&lt;/a&gt;.
As of now, there are no improvements, but those may
come in the next few days; feel free to suggest ideas.
</summary>
		<content type="html">&lt;p&gt;I've updated my &lt;a href="http://billmill.org/ncaa_randomizer.html"&gt;NCAA bracket
randomizer&lt;/a&gt; for the 2010 field; check it out
&lt;a href="http://billmill.org/static/ncaa-bracket-randomizer/out.html"&gt;here&lt;/a&gt;.
As of now, there are no improvements, but those may
come in the next few days; feel free to suggest ideas.
</content>
	</entry>
	<entry>
		<title>Multi-Line Lambdas in Python Using the With Statement</title>
		<link href="http://billmill.org/multi_line_lambdas.html" />	
		<id>http://billmill.org/multi_line_lambdas.html</id>
		<updated>2009-08-20T22:55:00Z</updated>
		<summary type="html">&lt;p&gt;Python &lt;a 
href="http://www.artima.com/weblogs/viewpost.jsp?thread=147358"&gt;does not have 
multi-line lambdas&lt;/a&gt; because Guido dislikes them aesthetically. However, with 
just a bit of introspection, code like this is possible:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;with&lt;/span&gt; each([&lt;span style="color: #009999"&gt;12&lt;/span&gt;, &lt;span style="color: #009999"&gt;14&lt;/span&gt;, &lt;span style="color: #009999"&gt;16&lt;/span&gt;]):
&lt;span style="font-weight: bold"&gt;...&lt;/span&gt;   &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
&lt;span style="font-weight: bold"&gt;...&lt;/span&gt;     &lt;span style="font-weight: bold"&gt;print&lt;/span&gt; x
&lt;span style="font-weight: bold"&gt;...&lt;/span&gt;     &lt;span style="font-weight: bold"&gt;print&lt;/span&gt; x&lt;span style="font-weight: bold"&gt;+&lt;/span&gt;&lt;span style="color: #009999"&gt;1&lt;/span&gt;
&lt;span style="font-weight: bold"&gt;...&lt;/span&gt;  
&lt;span style="color: #009999"&gt;12&lt;/span&gt;
&lt;span style="color: #009999"&gt;13&lt;/span&gt;
&lt;span style="color: #009999"&gt;14&lt;/span&gt;
&lt;span style="color: #009999"&gt;15&lt;/span&gt;
&lt;span style="color: #009999"&gt;16&lt;/span&gt;
&lt;span style="color: #009999"&gt;17&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I'll say a bit about my motivation for creating code like this, show how 
easy it is to write, and then I'll argue that code like this is both pythonic 
and aesthetically appealing in some circumstances.

&lt;p&gt;&lt;h2&gt;A Mystery Solved (By Holmes Himself!)&lt;/h2&gt;

&lt;p&gt;When I first saw code using the &lt;code&gt;with&lt;/code&gt; statement, my hope was 
that it would be able to be used somewhat like Haskell's &lt;a 
href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29#More_complex_examples"&gt;Where 
clause&lt;/a&gt; or Ruby's &lt;a 
href="http://allaboutruby.wordpress.com/2006/01/20/ruby-blocks-101/"&gt;blocks&lt;/a&gt;.  
When I dug into the &lt;a 
href="http://www.python.org/dev/peps/pep-0343/"&gt;spec&lt;/a&gt;, I was disappointed to 
discover that if it was possible, it wasn't easy, and I pushed the thought 
aside.

&lt;p&gt;That was a couple years ago, and I didn't give it a moment's thought until I 
saw &lt;a 
href="http://www.mechanicalcat.net/richard/log/Python/Something_I_m_working_on.3"&gt;a 
blog post&lt;/a&gt; by Richard Jones that uses a &lt;code&gt;with&lt;/code&gt; statement in exactly 
the way I had considered impossible up to now. I spent a few hours trying to 
figure it out, but I was stumped, so I put up &lt;a 
href="http://stackoverflow.com/questions/1255914/finding-functions-defined-in-a-with-block"&gt;a 
question&lt;/a&gt; on Stack Overflow to see if somebody could show me how he did it.

&lt;p&gt;Within a few hours, &lt;a 
href="http://en.wikipedia.org/wiki/Alex_Martelli"&gt;Alex Martelli&lt;/a&gt; himself 
chimed in with a wonderful solution. The gist of the answer is that you can use 
the &lt;code&gt;inspect&lt;/code&gt; module to access the &lt;a 
href="http://www.python.org/doc/2.5.2/lib/typecontextmanager.html"&gt;context 
manager&lt;/a&gt;'s calling scope, and figure out what variables have been defined 
between its &lt;code&gt;__enter__&lt;/code&gt; and &lt;code&gt;__exit__&lt;/code&gt; functions. I'm 
glad I asked aloud, because even if I had stumbled close to the solution, I 
surely wouldn't have come up with one as complete as his.

&lt;p&gt;&lt;h2&gt;The How&lt;/h2&gt;

&lt;p&gt;Once I had Alex's proof of concept code in hand, I went to work making it do 
what I'd had in my head so long ago. In about an hour, I was able to write code 
that looks like this:

&lt;div class="highlight"&gt;&lt;pre&gt;@accepts_block
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;each&lt;/span&gt;(iterable, block):
  &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; i &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; iterable:
      block(i)

&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; each([&lt;span style="color: #bb8844"&gt;&amp;quot;twelve&amp;quot;&lt;/span&gt;, &lt;span style="color: #bb8844"&gt;&amp;quot;fourteen&amp;quot;&lt;/span&gt;, &lt;span style="color: #bb8844"&gt;&amp;quot;sixteen&amp;quot;&lt;/span&gt;]):
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
    &lt;span style="font-weight: bold"&gt;print&lt;/span&gt; x

@accepts_block
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;bmap&lt;/span&gt;(arr, block):
  &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; &lt;span style="color: #999999"&gt;map&lt;/span&gt;(block, arr)

&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; bmap([&lt;span style="color: #009999"&gt;1&lt;/span&gt;,&lt;span style="color: #009999"&gt;2&lt;/span&gt;,&lt;span style="color: #009999"&gt;3&lt;/span&gt;]) &lt;span style="font-weight: bold"&gt;as&lt;/span&gt; foo:
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
    &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; (&lt;span style="color: #999999"&gt;float&lt;/span&gt;(x) &lt;span style="font-weight: bold"&gt;+&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;) &lt;span style="font-weight: bold"&gt;/&lt;/span&gt; &lt;span style="color: #009999"&gt;2&lt;/span&gt;

&lt;span style="font-weight: bold"&gt;print&lt;/span&gt; foo &lt;span style="color: #999988; font-style: italic"&gt;# [1.0, 1.5, 2.0]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;What you see above are two functions which use a decorator giving them 
access to the function defined within the &lt;code&gt;with&lt;/code&gt; block. The 
decorator passes the block to the function as its last argument just &lt;a 
href="http://eli.thegreenplace.net/2006/04/18/understanding-ruby-blocks-procs-and-methods/"&gt;like 
in Ruby&lt;/a&gt;.

&lt;p&gt;To understand how this happens, you need to know how context managers work.  
Context managers consist of a class with &lt;code&gt;__enter__&lt;/code&gt; and 
&lt;code&gt;__exit__&lt;/code&gt; methods which are called upon entering the with block and 
upon exiting, just as you'd expect.

&lt;p&gt;Alex's solution involves scanning the scope of the calling function from the 
&lt;code&gt;__enter__&lt;/code&gt; and &lt;code&gt;__exit__&lt;/code&gt; methods, and pulling out the 
differences between them. These differences will be all the variables that were 
defined in the &lt;code&gt;with&lt;/code&gt; block. A sketch:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;class&lt;/span&gt; &lt;span style="color: #445588; font-weight: bold"&gt;FindInteresting&lt;/span&gt;(&lt;span style="color: #999999"&gt;object&lt;/span&gt;):
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__enter__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
    f &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; inspect&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;currentframe(&lt;span style="color: #009999"&gt;1&lt;/span&gt;)
    &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;already_defined &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;dict&lt;/span&gt;(f&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;f_locals)

  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__exit__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
    f &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; inspect&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;currentframe(&lt;span style="color: #009999"&gt;1&lt;/span&gt;)
    &lt;span style="color: #999988; font-style: italic"&gt;#pick out the differences between f.f_locals and self.already_defined&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;When we pick out the differences between the two, we need to be careful to 
check for names that have been redefined so that we don't miss out on new 
functions that reuse old names.

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__exit__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
  f &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; inspect&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;currentframe(&lt;span style="color: #009999"&gt;1&lt;/span&gt;)
  interesting &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; {}
  &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; n &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; f&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;f_locals:
    newf &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; f&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;f_locals[n]
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; n &lt;span style="font-weight: bold"&gt;not&lt;/span&gt; &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;already_defined:
      interesting[n] &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; newf
      &lt;span style="font-weight: bold"&gt;continue&lt;/span&gt;
    anf &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;already_defined[n]
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #999999"&gt;id&lt;/span&gt;(newf) &lt;span style="font-weight: bold"&gt;!=&lt;/span&gt; &lt;span style="color: #999999"&gt;id&lt;/span&gt;(anf):
      interesting[n] &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; newf
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;After this function has run, &lt;code&gt;interesting&lt;/code&gt; is a dictionary which 
(probably) contains all the names and values of the variables that have been 
redefined in the &lt;code&gt;with&lt;/code&gt; block.

&lt;p&gt;Because we have to use the &lt;code&gt;id&lt;/code&gt; check to determine if a name has 
been redefined, and Python sometimes caches objects in memory, our function can 
be fooled. In this case, &lt;code&gt;interesting&lt;/code&gt; will not detect 
&lt;code&gt;x&lt;/code&gt; because it's being redefined and cpython caches the low 
integers, so &lt;code&gt;id(x)&lt;/code&gt; will be the same for both &lt;code&gt;x&lt;/code&gt;s.

&lt;div class="highlight"&gt;&lt;pre&gt;x &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;
&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; FindInteresting:
  x &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In general, the cpython runtime is not aggressive about caching, but you 
should know that this possibility exists. If you use this technique, I 
recommend being strict about checking only newly defined functions, since 
there's no way to be sure if you missed any redefined names.

&lt;p&gt;To make the teaser code at the top of the article work, I just wrapped 
Alex's code into a decorator that returned a context manager, then called the 
function being decorated with the definitions that we found in the 
&lt;code&gt;interesting&lt;/code&gt; dictionary. The context manager's 
&lt;code&gt;__call__&lt;/code&gt; function gets overridden to allow you to pass in 
arguments for the function being decorated.

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;accepts_block&lt;/span&gt;(f):
  &lt;span style="font-weight: bold"&gt;class&lt;/span&gt; &lt;span style="color: #445588; font-weight: bold"&gt;BlockContextManager&lt;/span&gt;(&lt;span style="color: #999999"&gt;object&lt;/span&gt;):
    &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__call__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;, &lt;span style="font-weight: bold"&gt;*&lt;/span&gt;args, &lt;span style="font-weight: bold"&gt;**&lt;/span&gt;kwargs):
      &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;thefunction &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; functools&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;partial(f, &lt;span style="font-weight: bold"&gt;*&lt;/span&gt;args, &lt;span style="font-weight: bold"&gt;**&lt;/span&gt;kwargs)
      &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;

    &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__enter__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
      &lt;span style="color: #999988; font-style: italic"&gt;#do Alex&amp;#39;s magic, just as above&lt;/span&gt;
    
    &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__exit__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
      &lt;span style="color: #999988; font-style: italic"&gt;#make the interesting dictionary, just as above&lt;/span&gt;

      &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #999999"&gt;len&lt;/span&gt;(interesting) &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;:
        block &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;list&lt;/span&gt;(interesting&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;itervalues())[&lt;span style="color: #009999"&gt;0&lt;/span&gt;]
        &lt;span style="font-weight: bold"&gt;assert&lt;/span&gt; &lt;span style="color: #999999"&gt;isinstance&lt;/span&gt;(block, &lt;span style="color: #999999"&gt;type&lt;/span&gt;(&lt;span style="font-weight: bold"&gt;lambda&lt;/span&gt;:&lt;span style="color: #999999"&gt;None&lt;/span&gt;))
        &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;thefunction(block)

  &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; BlockContextManager()
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;It looks complicated and nested, but all it's doing is saving the function 
and all its arguments, grabbing the definitions from the with block, making 
sure there's only one definition and it's a function, then tacking it onto the 
end of the arguments list for the function and calling it. Phew.

&lt;p&gt;The code above handles the case where you don't need to store the result of
the function being decorated:

&lt;div class="highlight"&gt;&lt;pre&gt;@accepts_block
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;each&lt;/span&gt;(iterable, block):
  &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; i &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; iterable:
    block(i)
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But what if we want to store the result? Turns out, we can further abuse the 
&lt;code&gt;with&lt;/code&gt; block by hijacking its &lt;code&gt;as&lt;/code&gt; clause. Because a 
variable defined in the &lt;code&gt;as&lt;/code&gt; clause gets detected by Alex's code, we 
can use the inspect module to change that variable so that after the with block 
it reflects the result of our computation.

&lt;p&gt;First we check to see if we probably have a block and a variable in the as 
statement, then we reach in and store our result there if we are in that case:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__exit__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
  &lt;span style="color: #999988; font-style: italic"&gt;#exactly as before; frame = inspect.currentframe(1)&lt;/span&gt;

  &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #999999"&gt;len&lt;/span&gt;(interesting) &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;:
    &lt;span style="color: #999988; font-style: italic"&gt;#exactly the same as before&lt;/span&gt;
  &lt;span style="font-weight: bold"&gt;elif&lt;/span&gt; &lt;span style="color: #999999"&gt;len&lt;/span&gt;(interesting) &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; &lt;span style="color: #009999"&gt;2&lt;/span&gt;:
    block &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;None&lt;/span&gt;
    savename &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;None&lt;/span&gt;
    &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; n,v &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; interesting&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;iteritems():
      &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #999999"&gt;isinstance&lt;/span&gt;(v, &lt;span style="color: #999999"&gt;type&lt;/span&gt;(&lt;span style="font-weight: bold"&gt;lambda&lt;/span&gt;:&lt;span style="color: #999999"&gt;None&lt;/span&gt;)): block &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; v
      &lt;span style="font-weight: bold"&gt;else&lt;/span&gt;: savename &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; n

    &lt;span style="font-weight: bold"&gt;assert&lt;/span&gt; savename &lt;span style="font-weight: bold"&gt;and&lt;/span&gt; &lt;span style="color: #999999"&gt;isinstance&lt;/span&gt;(block, &lt;span style="color: #999999"&gt;type&lt;/span&gt;(&lt;span style="font-weight: bold"&gt;lambda&lt;/span&gt;:&lt;span style="color: #999999"&gt;None&lt;/span&gt;))

    frame&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;f_locals[savename] &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;thefunction(block)
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Which lets us do this:

&lt;div class="highlight"&gt;&lt;pre&gt;@accepts_block
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;bmap&lt;/span&gt;(iterable, block):
  &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; &lt;span style="color: #999999"&gt;map&lt;/span&gt;(block, iterable)
  
&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; bmap([&lt;span style="color: #009999"&gt;1&lt;/span&gt;,&lt;span style="color: #009999"&gt;2&lt;/span&gt;,&lt;span style="color: #009999"&gt;3&lt;/span&gt;]) &lt;span style="font-weight: bold"&gt;as&lt;/span&gt; result:
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
    &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; x&lt;span style="font-weight: bold"&gt;**&lt;/span&gt;&lt;span style="color: #009999"&gt;2&lt;/span&gt;

&lt;span style="font-weight: bold"&gt;print&lt;/span&gt; result &lt;span style="color: #999988; font-style: italic"&gt;#[1,4,9]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This time, we're really taking a leap by assuming that if we find a callable 
and any other variable, that the variable is where we want to store our 
results. This can lead to somewhat unexpected results:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; bmap([&lt;span style="color: #009999"&gt;1&lt;/span&gt;,&lt;span style="color: #009999"&gt;2&lt;/span&gt;,&lt;span style="color: #009999"&gt;3&lt;/span&gt;]):
  not_a_result &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;12&lt;/span&gt;
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
    &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; x&lt;span style="font-weight: bold"&gt;**&lt;/span&gt;&lt;span style="color: #009999"&gt;2&lt;/span&gt;

&lt;span style="font-weight: bold"&gt;print&lt;/span&gt; not_a_result &lt;span style="color: #999988; font-style: italic"&gt;# [1,4,9] instead of 12&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;That's my extremely long-winded description of how to abuse the with 
operator. If you want to see the full function and the super-lame test code I 
wrote, you can &lt;a 
href="http://github.com/llimllib/Python-Multiline-Lambdas/tree/master"&gt;head on 
over to github&lt;/a&gt; and check it out.

&lt;p&gt;&lt;h2&gt;Aesthetics&lt;/h2&gt;

&lt;p&gt;It should be clear from all of the disclaimers I've had to put into this 
article that this technique is of limited use in Python as it stands today.  
I'd like to make an argument that it suggests some nice syntactic sugar for 
python to support someday, while remaining totally ignorant of the actual 
difficulties of putting it into the language.

&lt;p&gt;To do so, I'll start by posting the motivating example for decorators from 
&lt;a href="http://www.python.org/dev/peps/pep-0318/"&gt;the relevant PEP&lt;/a&gt;. It 
argues that this code:

&lt;p&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;foo&lt;/span&gt;(cls):
  &lt;span style="font-weight: bold"&gt;pass&lt;/span&gt;
foo &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; synchronized(lock)(foo)
foo &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;classmethod&lt;/span&gt;(foo)
&lt;/pre&gt;&lt;/div&gt;


is not nearly as readable as this code:

&lt;p&gt;&lt;div class="highlight"&gt;&lt;pre&gt;@classmethod
@synchronized(lock)
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;foo&lt;/span&gt;(cls):
  &lt;span style="font-weight: bold"&gt;pass&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The main problem with the readability of the first snippet is not that it 
requires 2 redefinitions and 4 repetitions of &lt;code&gt;foo&lt;/code&gt;. Rather, the 
main problem is that it places the cart before the horse by putting the 
function body ahead of the declarations that are required to understand it.

&lt;p&gt;Similarly, when we define callback functions before we use them, we're 
required to define the function body before the place where it will be actually 
used. Often, we see:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;handle_click&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
  foo &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;flim()
  &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; foo:
    &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;flam(foo)

onClick(handle_click)
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;When it would be clearer to write:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; onClick():
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
    foo &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;flim()
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; foo:
      &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;flam()
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Which I find much more appealing.

&lt;p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;I expect that there's no way that syntax like this could be officially 
supported by Python, both because of syntactic constraints and the 
&lt;acronym="Benevolent Dictator For Life"&gt;BDFL&lt;/a&gt;'s aesthetic concerns. I do 
think it is a neat exercise in pushing the Python interpreter and syntax past 
where they want to go, and I hope that it gives some food for thought on an 
interesting Python syntax.

&lt;p&gt;I'm excited to see where Richard Jones goes with his &lt;a 
href="http://www.mechanicalcat.net/richard/log/Python/Something_I_m_working_on.7"&gt;project&lt;/a&gt;, 
and the design choices that he makes in it, since he's pushing the boundaries 
of Python design. Many thanks to him and Alex Martelli for sending me down 
quite an enjoyable path.

&lt;p&gt;Finally, in case you missed it above, go ahead and &lt;a 
href="http://github.com/llimllib/Python-Multiline-Lambdas/tree/master"&gt;take a 
look at the code&lt;/a&gt; on github.

&lt;p&gt;If you want to leave a comment, I suggest leaving it on &lt;a href="http://www.reddit.com/r/Python/comments/9cnaw/multiline_lambdas_in_python_using_the_with/"&gt;reddit&lt;/a&gt;.

&lt;p&gt;&lt;h2&gt;Update:&lt;/h2&gt; Someone &lt;a
href="http://code.google.com/p/ouspg/wiki/AnonymousBlocksInPython?ts=1253546882&amp;updated=AnonymousBlocksInPython"&gt;has&lt;/a&gt; taken this technique a bit farther,
using some bytecode hackery.
</summary>
		<content type="html">&lt;p&gt;Python &lt;a 
href="http://www.artima.com/weblogs/viewpost.jsp?thread=147358"&gt;does not have 
multi-line lambdas&lt;/a&gt; because Guido dislikes them aesthetically. However, with 
just a bit of introspection, code like this is possible:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span style="font-weight: bold"&gt;with&lt;/span&gt; each([&lt;span style="color: #009999"&gt;12&lt;/span&gt;, &lt;span style="color: #009999"&gt;14&lt;/span&gt;, &lt;span style="color: #009999"&gt;16&lt;/span&gt;]):
&lt;span style="font-weight: bold"&gt;...&lt;/span&gt;   &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
&lt;span style="font-weight: bold"&gt;...&lt;/span&gt;     &lt;span style="font-weight: bold"&gt;print&lt;/span&gt; x
&lt;span style="font-weight: bold"&gt;...&lt;/span&gt;     &lt;span style="font-weight: bold"&gt;print&lt;/span&gt; x&lt;span style="font-weight: bold"&gt;+&lt;/span&gt;&lt;span style="color: #009999"&gt;1&lt;/span&gt;
&lt;span style="font-weight: bold"&gt;...&lt;/span&gt;  
&lt;span style="color: #009999"&gt;12&lt;/span&gt;
&lt;span style="color: #009999"&gt;13&lt;/span&gt;
&lt;span style="color: #009999"&gt;14&lt;/span&gt;
&lt;span style="color: #009999"&gt;15&lt;/span&gt;
&lt;span style="color: #009999"&gt;16&lt;/span&gt;
&lt;span style="color: #009999"&gt;17&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;I'll say a bit about my motivation for creating code like this, show how 
easy it is to write, and then I'll argue that code like this is both pythonic 
and aesthetically appealing in some circumstances.

&lt;p&gt;&lt;h2&gt;A Mystery Solved (By Holmes Himself!)&lt;/h2&gt;

&lt;p&gt;When I first saw code using the &lt;code&gt;with&lt;/code&gt; statement, my hope was 
that it would be able to be used somewhat like Haskell's &lt;a 
href="http://en.wikipedia.org/wiki/Haskell_%28programming_language%29#More_complex_examples"&gt;Where 
clause&lt;/a&gt; or Ruby's &lt;a 
href="http://allaboutruby.wordpress.com/2006/01/20/ruby-blocks-101/"&gt;blocks&lt;/a&gt;.  
When I dug into the &lt;a 
href="http://www.python.org/dev/peps/pep-0343/"&gt;spec&lt;/a&gt;, I was disappointed to 
discover that if it was possible, it wasn't easy, and I pushed the thought 
aside.

&lt;p&gt;That was a couple years ago, and I didn't give it a moment's thought until I 
saw &lt;a 
href="http://www.mechanicalcat.net/richard/log/Python/Something_I_m_working_on.3"&gt;a 
blog post&lt;/a&gt; by Richard Jones that uses a &lt;code&gt;with&lt;/code&gt; statement in exactly 
the way I had considered impossible up to now. I spent a few hours trying to 
figure it out, but I was stumped, so I put up &lt;a 
href="http://stackoverflow.com/questions/1255914/finding-functions-defined-in-a-with-block"&gt;a 
question&lt;/a&gt; on Stack Overflow to see if somebody could show me how he did it.

&lt;p&gt;Within a few hours, &lt;a 
href="http://en.wikipedia.org/wiki/Alex_Martelli"&gt;Alex Martelli&lt;/a&gt; himself 
chimed in with a wonderful solution. The gist of the answer is that you can use 
the &lt;code&gt;inspect&lt;/code&gt; module to access the &lt;a 
href="http://www.python.org/doc/2.5.2/lib/typecontextmanager.html"&gt;context 
manager&lt;/a&gt;'s calling scope, and figure out what variables have been defined 
between its &lt;code&gt;__enter__&lt;/code&gt; and &lt;code&gt;__exit__&lt;/code&gt; functions. I'm 
glad I asked aloud, because even if I had stumbled close to the solution, I 
surely wouldn't have come up with one as complete as his.

&lt;p&gt;&lt;h2&gt;The How&lt;/h2&gt;

&lt;p&gt;Once I had Alex's proof of concept code in hand, I went to work making it do 
what I'd had in my head so long ago. In about an hour, I was able to write code 
that looks like this:

&lt;div class="highlight"&gt;&lt;pre&gt;@accepts_block
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;each&lt;/span&gt;(iterable, block):
  &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; i &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; iterable:
      block(i)

&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; each([&lt;span style="color: #bb8844"&gt;&amp;quot;twelve&amp;quot;&lt;/span&gt;, &lt;span style="color: #bb8844"&gt;&amp;quot;fourteen&amp;quot;&lt;/span&gt;, &lt;span style="color: #bb8844"&gt;&amp;quot;sixteen&amp;quot;&lt;/span&gt;]):
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
    &lt;span style="font-weight: bold"&gt;print&lt;/span&gt; x

@accepts_block
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;bmap&lt;/span&gt;(arr, block):
  &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; &lt;span style="color: #999999"&gt;map&lt;/span&gt;(block, arr)

&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; bmap([&lt;span style="color: #009999"&gt;1&lt;/span&gt;,&lt;span style="color: #009999"&gt;2&lt;/span&gt;,&lt;span style="color: #009999"&gt;3&lt;/span&gt;]) &lt;span style="font-weight: bold"&gt;as&lt;/span&gt; foo:
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
    &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; (&lt;span style="color: #999999"&gt;float&lt;/span&gt;(x) &lt;span style="font-weight: bold"&gt;+&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;) &lt;span style="font-weight: bold"&gt;/&lt;/span&gt; &lt;span style="color: #009999"&gt;2&lt;/span&gt;

&lt;span style="font-weight: bold"&gt;print&lt;/span&gt; foo &lt;span style="color: #999988; font-style: italic"&gt;# [1.0, 1.5, 2.0]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;What you see above are two functions which use a decorator giving them 
access to the function defined within the &lt;code&gt;with&lt;/code&gt; block. The 
decorator passes the block to the function as its last argument just &lt;a 
href="http://eli.thegreenplace.net/2006/04/18/understanding-ruby-blocks-procs-and-methods/"&gt;like 
in Ruby&lt;/a&gt;.

&lt;p&gt;To understand how this happens, you need to know how context managers work.  
Context managers consist of a class with &lt;code&gt;__enter__&lt;/code&gt; and 
&lt;code&gt;__exit__&lt;/code&gt; methods which are called upon entering the with block and 
upon exiting, just as you'd expect.

&lt;p&gt;Alex's solution involves scanning the scope of the calling function from the 
&lt;code&gt;__enter__&lt;/code&gt; and &lt;code&gt;__exit__&lt;/code&gt; methods, and pulling out the 
differences between them. These differences will be all the variables that were 
defined in the &lt;code&gt;with&lt;/code&gt; block. A sketch:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;class&lt;/span&gt; &lt;span style="color: #445588; font-weight: bold"&gt;FindInteresting&lt;/span&gt;(&lt;span style="color: #999999"&gt;object&lt;/span&gt;):
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__enter__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
    f &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; inspect&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;currentframe(&lt;span style="color: #009999"&gt;1&lt;/span&gt;)
    &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;already_defined &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;dict&lt;/span&gt;(f&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;f_locals)

  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__exit__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
    f &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; inspect&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;currentframe(&lt;span style="color: #009999"&gt;1&lt;/span&gt;)
    &lt;span style="color: #999988; font-style: italic"&gt;#pick out the differences between f.f_locals and self.already_defined&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;When we pick out the differences between the two, we need to be careful to 
check for names that have been redefined so that we don't miss out on new 
functions that reuse old names.

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__exit__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
  f &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; inspect&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;currentframe(&lt;span style="color: #009999"&gt;1&lt;/span&gt;)
  interesting &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; {}
  &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; n &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; f&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;f_locals:
    newf &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; f&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;f_locals[n]
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; n &lt;span style="font-weight: bold"&gt;not&lt;/span&gt; &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;already_defined:
      interesting[n] &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; newf
      &lt;span style="font-weight: bold"&gt;continue&lt;/span&gt;
    anf &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;already_defined[n]
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #999999"&gt;id&lt;/span&gt;(newf) &lt;span style="font-weight: bold"&gt;!=&lt;/span&gt; &lt;span style="color: #999999"&gt;id&lt;/span&gt;(anf):
      interesting[n] &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; newf
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;After this function has run, &lt;code&gt;interesting&lt;/code&gt; is a dictionary which 
(probably) contains all the names and values of the variables that have been 
redefined in the &lt;code&gt;with&lt;/code&gt; block.

&lt;p&gt;Because we have to use the &lt;code&gt;id&lt;/code&gt; check to determine if a name has 
been redefined, and Python sometimes caches objects in memory, our function can 
be fooled. In this case, &lt;code&gt;interesting&lt;/code&gt; will not detect 
&lt;code&gt;x&lt;/code&gt; because it's being redefined and cpython caches the low 
integers, so &lt;code&gt;id(x)&lt;/code&gt; will be the same for both &lt;code&gt;x&lt;/code&gt;s.

&lt;div class="highlight"&gt;&lt;pre&gt;x &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;
&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; FindInteresting:
  x &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In general, the cpython runtime is not aggressive about caching, but you 
should know that this possibility exists. If you use this technique, I 
recommend being strict about checking only newly defined functions, since 
there's no way to be sure if you missed any redefined names.

&lt;p&gt;To make the teaser code at the top of the article work, I just wrapped 
Alex's code into a decorator that returned a context manager, then called the 
function being decorated with the definitions that we found in the 
&lt;code&gt;interesting&lt;/code&gt; dictionary. The context manager's 
&lt;code&gt;__call__&lt;/code&gt; function gets overridden to allow you to pass in 
arguments for the function being decorated.

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;accepts_block&lt;/span&gt;(f):
  &lt;span style="font-weight: bold"&gt;class&lt;/span&gt; &lt;span style="color: #445588; font-weight: bold"&gt;BlockContextManager&lt;/span&gt;(&lt;span style="color: #999999"&gt;object&lt;/span&gt;):
    &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__call__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;, &lt;span style="font-weight: bold"&gt;*&lt;/span&gt;args, &lt;span style="font-weight: bold"&gt;**&lt;/span&gt;kwargs):
      &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;thefunction &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; functools&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;partial(f, &lt;span style="font-weight: bold"&gt;*&lt;/span&gt;args, &lt;span style="font-weight: bold"&gt;**&lt;/span&gt;kwargs)
      &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;

    &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__enter__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
      &lt;span style="color: #999988; font-style: italic"&gt;#do Alex&amp;#39;s magic, just as above&lt;/span&gt;
    
    &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__exit__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
      &lt;span style="color: #999988; font-style: italic"&gt;#make the interesting dictionary, just as above&lt;/span&gt;

      &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #999999"&gt;len&lt;/span&gt;(interesting) &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;:
        block &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;list&lt;/span&gt;(interesting&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;itervalues())[&lt;span style="color: #009999"&gt;0&lt;/span&gt;]
        &lt;span style="font-weight: bold"&gt;assert&lt;/span&gt; &lt;span style="color: #999999"&gt;isinstance&lt;/span&gt;(block, &lt;span style="color: #999999"&gt;type&lt;/span&gt;(&lt;span style="font-weight: bold"&gt;lambda&lt;/span&gt;:&lt;span style="color: #999999"&gt;None&lt;/span&gt;))
        &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;thefunction(block)

  &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; BlockContextManager()
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;It looks complicated and nested, but all it's doing is saving the function 
and all its arguments, grabbing the definitions from the with block, making 
sure there's only one definition and it's a function, then tacking it onto the 
end of the arguments list for the function and calling it. Phew.

&lt;p&gt;The code above handles the case where you don't need to store the result of
the function being decorated:

&lt;div class="highlight"&gt;&lt;pre&gt;@accepts_block
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;each&lt;/span&gt;(iterable, block):
  &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; i &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; iterable:
    block(i)
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;But what if we want to store the result? Turns out, we can further abuse the 
&lt;code&gt;with&lt;/code&gt; block by hijacking its &lt;code&gt;as&lt;/code&gt; clause. Because a 
variable defined in the &lt;code&gt;as&lt;/code&gt; clause gets detected by Alex's code, we 
can use the inspect module to change that variable so that after the with block 
it reflects the result of our computation.

&lt;p&gt;First we check to see if we probably have a block and a variable in the as 
statement, then we reach in and store our result there if we are in that case:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;__exit__&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
  &lt;span style="color: #999988; font-style: italic"&gt;#exactly as before; frame = inspect.currentframe(1)&lt;/span&gt;

  &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #999999"&gt;len&lt;/span&gt;(interesting) &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; &lt;span style="color: #009999"&gt;1&lt;/span&gt;:
    &lt;span style="color: #999988; font-style: italic"&gt;#exactly the same as before&lt;/span&gt;
  &lt;span style="font-weight: bold"&gt;elif&lt;/span&gt; &lt;span style="color: #999999"&gt;len&lt;/span&gt;(interesting) &lt;span style="font-weight: bold"&gt;==&lt;/span&gt; &lt;span style="color: #009999"&gt;2&lt;/span&gt;:
    block &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;None&lt;/span&gt;
    savename &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;None&lt;/span&gt;
    &lt;span style="font-weight: bold"&gt;for&lt;/span&gt; n,v &lt;span style="font-weight: bold"&gt;in&lt;/span&gt; interesting&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;iteritems():
      &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; &lt;span style="color: #999999"&gt;isinstance&lt;/span&gt;(v, &lt;span style="color: #999999"&gt;type&lt;/span&gt;(&lt;span style="font-weight: bold"&gt;lambda&lt;/span&gt;:&lt;span style="color: #999999"&gt;None&lt;/span&gt;)): block &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; v
      &lt;span style="font-weight: bold"&gt;else&lt;/span&gt;: savename &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; n

    &lt;span style="font-weight: bold"&gt;assert&lt;/span&gt; savename &lt;span style="font-weight: bold"&gt;and&lt;/span&gt; &lt;span style="color: #999999"&gt;isinstance&lt;/span&gt;(block, &lt;span style="color: #999999"&gt;type&lt;/span&gt;(&lt;span style="font-weight: bold"&gt;lambda&lt;/span&gt;:&lt;span style="color: #999999"&gt;None&lt;/span&gt;))

    frame&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;f_locals[savename] &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;thefunction(block)
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Which lets us do this:

&lt;div class="highlight"&gt;&lt;pre&gt;@accepts_block
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;bmap&lt;/span&gt;(iterable, block):
  &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; &lt;span style="color: #999999"&gt;map&lt;/span&gt;(block, iterable)
  
&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; bmap([&lt;span style="color: #009999"&gt;1&lt;/span&gt;,&lt;span style="color: #009999"&gt;2&lt;/span&gt;,&lt;span style="color: #009999"&gt;3&lt;/span&gt;]) &lt;span style="font-weight: bold"&gt;as&lt;/span&gt; result:
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
    &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; x&lt;span style="font-weight: bold"&gt;**&lt;/span&gt;&lt;span style="color: #009999"&gt;2&lt;/span&gt;

&lt;span style="font-weight: bold"&gt;print&lt;/span&gt; result &lt;span style="color: #999988; font-style: italic"&gt;#[1,4,9]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;This time, we're really taking a leap by assuming that if we find a callable 
and any other variable, that the variable is where we want to store our 
results. This can lead to somewhat unexpected results:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; bmap([&lt;span style="color: #009999"&gt;1&lt;/span&gt;,&lt;span style="color: #009999"&gt;2&lt;/span&gt;,&lt;span style="color: #009999"&gt;3&lt;/span&gt;]):
  not_a_result &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #009999"&gt;12&lt;/span&gt;
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(x):
    &lt;span style="font-weight: bold"&gt;return&lt;/span&gt; x&lt;span style="font-weight: bold"&gt;**&lt;/span&gt;&lt;span style="color: #009999"&gt;2&lt;/span&gt;

&lt;span style="font-weight: bold"&gt;print&lt;/span&gt; not_a_result &lt;span style="color: #999988; font-style: italic"&gt;# [1,4,9] instead of 12&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;That's my extremely long-winded description of how to abuse the with 
operator. If you want to see the full function and the super-lame test code I 
wrote, you can &lt;a 
href="http://github.com/llimllib/Python-Multiline-Lambdas/tree/master"&gt;head on 
over to github&lt;/a&gt; and check it out.

&lt;p&gt;&lt;h2&gt;Aesthetics&lt;/h2&gt;

&lt;p&gt;It should be clear from all of the disclaimers I've had to put into this 
article that this technique is of limited use in Python as it stands today.  
I'd like to make an argument that it suggests some nice syntactic sugar for 
python to support someday, while remaining totally ignorant of the actual 
difficulties of putting it into the language.

&lt;p&gt;To do so, I'll start by posting the motivating example for decorators from 
&lt;a href="http://www.python.org/dev/peps/pep-0318/"&gt;the relevant PEP&lt;/a&gt;. It 
argues that this code:

&lt;p&gt;&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;foo&lt;/span&gt;(cls):
  &lt;span style="font-weight: bold"&gt;pass&lt;/span&gt;
foo &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; synchronized(lock)(foo)
foo &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;classmethod&lt;/span&gt;(foo)
&lt;/pre&gt;&lt;/div&gt;


is not nearly as readable as this code:

&lt;p&gt;&lt;div class="highlight"&gt;&lt;pre&gt;@classmethod
@synchronized(lock)
&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;foo&lt;/span&gt;(cls):
  &lt;span style="font-weight: bold"&gt;pass&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;The main problem with the readability of the first snippet is not that it 
requires 2 redefinitions and 4 repetitions of &lt;code&gt;foo&lt;/code&gt;. Rather, the 
main problem is that it places the cart before the horse by putting the 
function body ahead of the declarations that are required to understand it.

&lt;p&gt;Similarly, when we define callback functions before we use them, we're 
required to define the function body before the place where it will be actually 
used. Often, we see:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;handle_click&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
  foo &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;flim()
  &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; foo:
    &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;flam(foo)

onClick(handle_click)
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;When it would be clearer to write:

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span style="font-weight: bold"&gt;with&lt;/span&gt; onClick():
  &lt;span style="font-weight: bold"&gt;def&lt;/span&gt; &lt;span style="color: #990000; font-weight: bold"&gt;_&lt;/span&gt;(&lt;span style="color: #999999"&gt;self&lt;/span&gt;):
    foo &lt;span style="font-weight: bold"&gt;=&lt;/span&gt; &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;flim()
    &lt;span style="font-weight: bold"&gt;if&lt;/span&gt; foo:
      &lt;span style="color: #999999"&gt;self&lt;/span&gt;&lt;span style="font-weight: bold"&gt;.&lt;/span&gt;flam()
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Which I find much more appealing.

&lt;p&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;I expect that there's no way that syntax like this could be officially 
supported by Python, both because of syntactic constraints and the 
&lt;acronym="Benevolent Dictator For Life"&gt;BDFL&lt;/a&gt;'s aesthetic concerns. I do 
think it is a neat exercise in pushing the Python interpreter and syntax past 
where they want to go, and I hope that it gives some food for thought on an 
interesting Python syntax.

&lt;p&gt;I'm excited to see where Richard Jones goes with his &lt;a 
href="http://www.mechanicalcat.net/richard/log/Python/Something_I_m_working_on.7"&gt;project&lt;/a&gt;, 
and the design choices that he makes in it, since he's pushing the boundaries 
of Python design. Many thanks to him and Alex Martelli for sending me down 
quite an enjoyable path.

&lt;p&gt;Finally, in case you missed it above, go ahead and &lt;a 
href="http://github.com/llimllib/Python-Multiline-Lambdas/tree/master"&gt;take a 
look at the code&lt;/a&gt; on github.

&lt;p&gt;If you want to leave a comment, I suggest leaving it on &lt;a href="http://www.reddit.com/r/Python/comments/9cnaw/multiline_lambdas_in_python_using_the_with/"&gt;reddit&lt;/a&gt;.

&lt;p&gt;&lt;h2&gt;Update:&lt;/h2&gt; Someone &lt;a
href="http://code.google.com/p/ouspg/wiki/AnonymousBlocksInPython?ts=1253546882&amp;updated=AnonymousBlocksInPython"&gt;has&lt;/a&gt; taken this technique a bit farther,
using some bytecode hackery.
</content>
	</entry>
	<entry>
		<title>What Gladwell is Missing: Institutional Memory</title>
		<link href="http://billmill.org/institutional_memory.html" />	
		<id>http://billmill.org/institutional_memory.html</id>
		<updated>2009-05-31T16:50:00Z</updated>
		<summary type="html">&lt;p&gt;Malcolm Gladwell's recent &lt;a
href="http://www.newyorker.com/reporting/2009/05/11/090511fa_fact_gladwell?yrail"&gt;article&lt;/a&gt;,
ostensibly about how Davids can beat Goliaths, featured great praise for the
full-court press as a method for less-skilled teams to beat more-skilled ones.
He writes:

&lt;blockquote&gt;In the world of basketball, there is one story after another like
this about legendary games where David used the full-court press to beat
Goliath. Yet the puzzle of the press is that it has never become popular.
People look at upsets like Fordham over UMass and call them flukes. Basketball
sages point out that the press can be beaten by a well-coached team with adept
ball handlers and astute passers&amp;mdash;and that is true... Playing insurgent
basketball did not guarantee victory. It was simply the best chance an underdog
had of beating Goliath.&lt;/blockquote&gt;

&lt;p&gt;After his piece was &lt;a
href="http://galleyslaves.blogspot.com/2009/05/more-on-gladwell-press-etc.html"&gt;rightly&lt;/a&gt;
&lt;a
href="http://deadspin.com/5239721/malcolm-gladwell-wants-to-know-why-your-team-doesnt-press-more"&gt;criticized&lt;/a&gt; 
&lt;a
href="http://rivals.yahoo.com/ncaa/basketball/blog/the_dagger/post/Malcolm-Gladwell-still-talking-about-the-full-co?urn=ncaab,163209"&gt;all&lt;/a&gt;
&lt;a
href="http://rushthecourt.net/2009/05/05/gladwells-theory-on-full-court-pressure-is-the-only-outlier-here/"&gt;over&lt;/a&gt;
&lt;a
href="http://www.nbcnewyork.com/sports/basketball/Why-Dont-More-Basketball-Teams-Run-the-Press.html"&gt;the&lt;/a&gt; 
&lt;a
href="http://nymag.com/daily/intel/2009/05/malcolm_gladwell_isnt_a_basket.html"&gt;web&lt;/a&gt;,
ESPN &lt;a
href="http://sports.espn.go.com/espn/page2/story?page=simmons/090513"&gt;published&lt;/a&gt;
a long and interesting email conversation between him and Bill Simmons that
addressed the criticism. In it, Gladwell defended his column:

&lt;blockquote&gt;After my piece ran in &lt;em&gt;The New Yorker&lt;/em&gt;, one of the most common
responses I got was people saying, well, the reason more people don't use the
press is that it can be beaten with a well-coached team and a good point guard.
That is (A) absolutely true and (B) beside the point. The press doesn't
guarantee victory. It simply represents the underdog's best  chance of
victory&amp;hellip; I went to see a Lakers-Warriors game earlier this season, and
it was abundantly clear after five minutes that the Warriors' chances of
winning were, oh, no better than 10 percent. Why wouldn't you have a special
squad of trained pressers come in for five minutes a half and press Kobe and
Fisher?&amp;hellip;  Best case is that you rattle the Lakers and force
a half-dozen extra turnovers that turn out to be crucial. And if you lose, so
what? You were going to lose anyway.&lt;/blockquote&gt;

&lt;p&gt;Although lots of people have responded to this rebuttal, I haven't seen
anyone mention what I consider to be an important reason that many teams have
chosen not to implement full-court presses: &lt;strong&gt;Institutional
Memory&lt;/strong&gt;.

&lt;p&gt;Let's imagine that the Warriors had in fact, put on the press, and that it
had worked. The Warriors won against the vaunted Lakers! How would the team
respond? They would press more. When that worked to win some more games, they would
probably trade some of their players who were less well suited to the press to
make room for some younger, faster, fitter players. They would win a few more
games than they had been before. Everything's going good, right?

&lt;p&gt;Then they hit a snag; &lt;strong&gt;No team has won the NBA Championship by pressing
&lt;/strong&gt;. The Warriors could optimize like crazy for the press, but
they'd be training and working and trading and drafting to be, at best, a
pretty good team. But no NBA team wants to be a pretty good team&amp;mdash;they all
want to win championships.

&lt;p&gt;The mental exercise reveals what Gladwell has missed: the Warriors aren't
playing to win that game, or even the most games that season. They're playing
to try and win an NBA championship,
and to do so, they need to spend years trying to build up the institutional
memory of how to win games in the traditional way so that they can eventually beat
every team, not just to win more games than they did playing traditionally.

&lt;p&gt;All of this leads to a simple admonishment when analyzing organizations:
don't expect that the organization is optimizing for what you think they're
optimizing for. And when an organization seems to be acting in ways that are surprising to
you, look for metrics that may be more important to them than the ones you
expect.
</summary>
		<content type="html">&lt;p&gt;Malcolm Gladwell's recent &lt;a
href="http://www.newyorker.com/reporting/2009/05/11/090511fa_fact_gladwell?yrail"&gt;article&lt;/a&gt;,
ostensibly about how Davids can beat Goliaths, featured great praise for the
full-court press as a method for less-skilled teams to beat more-skilled ones.
He writes:

&lt;blockquote&gt;In the world of basketball, there is one story after another like
this about legendary games where David used the full-court press to beat
Goliath. Yet the puzzle of the press is that it has never become popular.
People look at upsets like Fordham over UMass and call them flukes. Basketball
sages point out that the press can be beaten by a well-coached team with adept
ball handlers and astute passers&amp;mdash;and that is true... Playing insurgent
basketball did not guarantee victory. It was simply the best chance an underdog
had of beating Goliath.&lt;/blockquote&gt;

&lt;p&gt;After his piece was &lt;a
href="http://galleyslaves.blogspot.com/2009/05/more-on-gladwell-press-etc.html"&gt;rightly&lt;/a&gt;
&lt;a
href="http://deadspin.com/5239721/malcolm-gladwell-wants-to-know-why-your-team-doesnt-press-more"&gt;criticized&lt;/a&gt; 
&lt;a
href="http://rivals.yahoo.com/ncaa/basketball/blog/the_dagger/post/Malcolm-Gladwell-still-talking-about-the-full-co?urn=ncaab,163209"&gt;all&lt;/a&gt;
&lt;a
href="http://rushthecourt.net/2009/05/05/gladwells-theory-on-full-court-pressure-is-the-only-outlier-here/"&gt;over&lt;/a&gt;
&lt;a
href="http://www.nbcnewyork.com/sports/basketball/Why-Dont-More-Basketball-Teams-Run-the-Press.html"&gt;the&lt;/a&gt; 
&lt;a
href="http://nymag.com/daily/intel/2009/05/malcolm_gladwell_isnt_a_basket.html"&gt;web&lt;/a&gt;,
ESPN &lt;a
href="http://sports.espn.go.com/espn/page2/story?page=simmons/090513"&gt;published&lt;/a&gt;
a long and interesting email conversation between him and Bill Simmons that
addressed the criticism. In it, Gladwell defended his column:

&lt;blockquote&gt;After my piece ran in &lt;em&gt;The New Yorker&lt;/em&gt;, one of the most common
responses I got was people saying, well, the reason more people don't use the
press is that it can be beaten with a well-coached team and a good point guard.
That is (A) absolutely true and (B) beside the point. The press doesn't
guarantee victory. It simply represents the underdog's best  chance of
victory&amp;hellip; I went to see a Lakers-Warriors game earlier this season, and
it was abundantly clear after five minutes that the Warriors' chances of
winning were, oh, no better than 10 percent. Why wouldn't you have a special
squad of trained pressers come in for five minutes a half and press Kobe and
Fisher?&amp;hellip;  Best case is that you rattle the Lakers and force
a half-dozen extra turnovers that turn out to be crucial. And if you lose, so
what? You were going to lose anyway.&lt;/blockquote&gt;

&lt;p&gt;Although lots of people have responded to this rebuttal, I haven't seen
anyone mention what I consider to be an important reason that many teams have
chosen not to implement full-court presses: &lt;strong&gt;Institutional
Memory&lt;/strong&gt;.

&lt;p&gt;Let's imagine that the Warriors had in fact, put on the press, and that it
had worked. The Warriors won against the vaunted Lakers! How would the team
respond? They would press more. When that worked to win some more games, they would
probably trade some of their players who were less well suited to the press to
make room for some younger, faster, fitter players. They would win a few more
games than they had been before. Everything's going good, right?

&lt;p&gt;Then they hit a snag; &lt;strong&gt;No team has won the NBA Championship by pressing
&lt;/strong&gt;. The Warriors could optimize like crazy for the press, but
they'd be training and working and trading and drafting to be, at best, a
pretty good team. But no NBA team wants to be a pretty good team&amp;mdash;they all
want to win championships.

&lt;p&gt;The mental exercise reveals what Gladwell has missed: the Warriors aren't
playing to win that game, or even the most games that season. They're playing
to try and win an NBA championship,
and to do so, they need to spend years trying to build up the institutional
memory of how to win games in the traditional way so that they can eventually beat
every team, not just to win more games than they did playing traditionally.

&lt;p&gt;All of this leads to a simple admonishment when analyzing organizations:
don't expect that the organization is optimizing for what you think they're
optimizing for. And when an organization seems to be acting in ways that are surprising to
you, look for metrics that may be more important to them than the ones you
expect.
</content>
	</entry>
</feed>
