Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2192
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Fun python 3.2 one-liner |
| Date | 2011-03-29 16:06 -0400 |
| References | <df2af546-af99-4e69-bc8e-38c21a045a29@z27g2000prz.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1381.1301429221.1189.python-list@python.org> (permalink) |
On 3/29/2011 5:50 AM, Raymond Hettinger wrote:
> from collections import Counter
> from itertools import product
>
> print('\n'.join('*'*(c//2000) for _,c in sorted(Counter(map(sum,
> product(range(6), repeat=8))).items())))
The line break makes that hard to read; the axis is not labeled (and
labels help understand the code). So my suggested revision is:
from collections import Counter
from itertools import product
print('\n'.join('{:2d}: {}'.format(i, '*'*(c//2000)) for i,c in sorted(
Counter(map(sum,product(range(6), repeat=8))).items() )))
0:
1:
2:
3:
4:
5:
6:
7: *
8: ***
9: *****
10: ********
11: ************
12: ******************
13: *************************
14: ********************************
15: *****************************************
16: *************************************************
17: ********************************************************
18: **************************************************************
19: ******************************************************************
20: *******************************************************************
21: ******************************************************************
22: **************************************************************
23: ********************************************************
24: *************************************************
25: *****************************************
26: ********************************
27: *************************
28: ******************
29: ************
30: ********
31: *****
32: ***
33: *
34:
35:
36:
37:
38:
39:
40:
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Next in thread | Find similar
Re: Fun python 3.2 one-liner Terry Reedy <tjreedy@udel.edu> - 2011-03-29 16:06 -0400
Re: Fun python 3.2 one-liner Martin De Kauwe <mdekauwe@gmail.com> - 2011-03-30 02:19 -0700
Re: Fun python 3.2 one-liner Chris Angelico <rosuav@gmail.com> - 2011-03-30 20:31 +1100
Re: Fun python 3.2 one-liner Raymond Hettinger <python@rcn.com> - 2011-03-30 16:39 -0700
Re: Fun python 3.2 one-liner Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2011-03-31 16:02 +1300
Re: Fun python 3.2 one-liner Daniel Fetchinson <fetchinson@googlemail.com> - 2011-04-05 15:38 +0200
Re: Fun python 3.2 one-liner Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-05 15:07 +0000
Re: Fun python 3.2 one-liner Chris Angelico <rosuav@gmail.com> - 2011-04-06 01:19 +1000
Re: Fun python 3.2 one-liner Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-05 17:48 +0000
Re: Fun python 3.2 one-liner Daniel Fetchinson <fetchinson@googlemail.com> - 2011-04-05 19:54 +0200
Re: Fun python 3.2 one-liner Raymond Hettinger <python@rcn.com> - 2011-04-05 17:10 -0700
Re: Fun python 3.2 one-liner Ben Finney <ben+python@benfinney.id.au> - 2011-04-06 13:59 +1000
Re: Fun python 3.2 one-liner Chris Angelico <rosuav@gmail.com> - 2011-04-06 11:34 +1000
Re: Fun python 3.2 one-liner Tim Wintle <tim.wintle@teamrubber.com> - 2011-04-05 16:04 +0100
csiph-web