Re: how to calculate reputation

2013-07-06 Thread DJC
On 03/07/13 02:05, Mark Janssen wrote: Hi all, this seems to be quite stupid question but I am "confused".. We set the initial value to 0, +1 for up-vote and -1 for down-vote! nice. I have a list of bool values True, False (True for up vote, False for down-vote).. submitted by users. should I t

Re: Fwd: Python for philosophers

2013-05-14 Thread DJC
On 14/05/13 09:34, Citizen Kant wrote: 2013/5/14 Steven D'Aprano On Tue, 14 May 2013 01:32:43 +0200, Citizen Kant wrote: An entity named Python must be somehow as a serpent. Don't forget that I'm with the freeing up of my memory, now I'm not trying to follow the path of what's told but actin

Re: Confusing Algorithm

2013-04-22 Thread DJC
On 22/04/13 13:39, RBotha wrote: I'm facing the following problem: """ In a city of towerblocks, Spiderman can “cover” all the towers by connecting the first tower with a spider-thread to the top of a later tower and then to a next tower and then to yet another tower until he reaches the end of

Re: Why are timezone aware and naive datetimes not distinct classes?

2013-03-11 Thread djc
On 11/03/13 17:27, Adam Tauno Williams wrote: Because date/time management in Python is *@*&@R&*(R *@&Y terrible! Period, full-stop, awful, crappy, lousy, and aggravating. The design is haphazard and error inducing. +1 -- djc -- http://mail.python.org/mailman/listinfo/python-list

Re: Thought of the day

2013-01-15 Thread DJC
On 15/01/13 16:48, Antoine Pitrou wrote: Steven D'Aprano pearwood.info> writes: A programmer had a problem, and thought Now he has "I know, I'll solve two it with threads!" problems. Host: Last week the Royal Festival Hall saw the first performance of a new logfile by one of the world's lea

Re: got stuck in equation

2013-01-02 Thread DJC
On 02/01/13 05:20, Ramchandra Apte wrote: On Tuesday, 1 January 2013 22:55:21 UTC+5:30, Usama Khan wrote: am just a begginer bro. . jus learnt if elif while nd for loop. . can u just display me the coding u want. .it could save my time that i have while searchning SN out. . i will give u that

Re: Good use for itertools.dropwhile and itertools.takewhile

2012-12-04 Thread DJC
On 04/12/12 17:18, Alexander Blinne wrote: Another neat solution with a little help from http://stackoverflow.com/questions/1701211/python-return-the-index-of-the-first-element-of-a-list-which-makes-a-passed-fun def split_product(p): w = p.split(" ") j = (i for i,v in enumer

Re: sort order for strings of digits

2012-10-31 Thread DJC
On 31/10/12 23:09, Steven D'Aprano wrote: On Wed, 31 Oct 2012 15:17:14 +0000, djc wrote: The best I can think of is to split the input sequence into two lists, sort each and then join them. According to your example code, you don't have to split the input because you already have

sort order for strings of digits

2012-10-31 Thread djc
, 101, 2000, '1a', '222 bb', 'a', 'a1', 'ab', 'acd', 'b a 4', 'bcd'] [str(x) for x in sorted(int(x) if x.isdigit() else x for x in n+s)] ['1', '2', '3', '10', '13', '31', '40', '101', '2000', '1a', '222 bb', 'a', 'a1', 'ab', 'acd', 'b a 4', 'bcd'] But not for Python 3 Python 3.2.3 (default, Oct 19 2012, 19:53:16) >>> sorted(n+s) ['1', '10', '101', '13', '1a', '2', '2000', '222 bb', '3', '31', '40', 'a', 'a1', 'ab', 'acd', 'b a 4', 'bcd'] >>> sorted(int(x) if x.isdigit() else x for x in n+s) Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: str() < int() >>> The best I can think of is to split the input sequence into two lists, sort each and then join them. -- djc -- http://mail.python.org/mailman/listinfo/python-list

Re: A desperate lunge for on-topic-ness

2012-10-21 Thread DJC
On 20/10/12 15:18, Grant Edwards wrote: On 2012-10-20, Dennis Lee Bieber wrote: Strangely, we've gone from 80-character fixed width displays to who-knows-what (if I drop my font size I can probably get nearly 200 characters across in full-screen mode)... But at the same time w

Re: color coding for numbers

2012-08-21 Thread DJC
On 21/08/12 12:55, Ulrich Eckhardt wrote: Am 21.08.2012 10:38, schrieb namenobodywa...@gmail.com: what is the best way Define "best" before asking such questions. ;) matplotlib.colors A module for co

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread DJC
On 19/08/12 15:25, Steven D'Aprano wrote: Not necessarily. Presumably you're scanning each page into a single string. Then only the pages containing a supplementary plane char will be bloated, which is likely to be rare. Especially since I don't expect your OCR application would recognise many n

Re: Looking for a good introduction to object oriented programming with Python

2012-08-06 Thread DJC
On 06/08/12 02:27, Steven D'Aprano wrote: On Sun, 05 Aug 2012 19:12:35 -0400, Roy Smith wrote: Good lord. I'd rather read C++ than UML. And I can't read C++. UML is under-rated. I certainly don't have any love of the 47 different flavors of diagram, but the basic idea of having a common gra

Re: Learning Python 2.4

2011-12-21 Thread DJC
On 21/12/11 02:13, Ashton Fagg wrote: > I got the impression the OP was learning programming in general (i.e. > from scratch) and not merely "learning Python". If this is the case it > shouldn't matter if they're merely learning the concepts as you can > always get up to speed on the differences l

Re: OT: Meaning of "monkey"

2010-03-29 Thread djc
Mensanator wrote: > On Mar 26, 2:44 pm, Phlip wrote: >> On Mar 26, 6:14 am, Luis M. González wrote: >> >>> Webmonkey, Greasemonkey, monkey-patching, Tracemonkey, Jägermonkey, >>> Spidermonkey, Mono (monkey in spanish), codemonkey, etc, etc, etc... >>> Monkeys everywhere. >>> Sorry for the off top

Re: should writing Unicode files be so slow

2010-03-21 Thread djc
Antoine Pitrou wrote: > Le Fri, 19 Mar 2010 17:18:17 +0000, djc a écrit : >> changing >> with open(filename, 'rU') as tabfile: to >> with codecs.open(filename, 'rU', 'utf-8', 'backslashreplace') as >> tabfile: >> >>

Re: should writing Unicode files be so slow

2010-03-19 Thread djc
Ben Finney wrote: > What happens, then, when you make a smaller program that deals with only > one file? > > What happens when you make a smaller program that only reads the file, > and doesn't write any? Or a different program that only writes a file, > and doesn't read any? > > It's these sort

Re: should writing Unicode files be so slow

2010-03-19 Thread djc
Ben Finney wrote: > djc writes: > >> I have a simple program to read a text (.csv) file > > Could you please: > > * simplify it further: make a minimal version that demonstrates the > difference you're seeing, without any extraneous stuff that doesn&#

should writing Unicode files be so slow

2010-03-18 Thread djc
I have a simple program to read a text (.csv) file and split it into several smaller files. Tonight I decided to write a unicode variant and was surprised at the difference in performance. Is there a better way? > from __future__ import with_statement > import codecs > > def _rowreader(filename,

Re: Iterate over group names in a regex match?

2010-01-19 Thread djc
Brian D wrote: > Here's a simple named group matching pattern: > s = "1,2,3" p = re.compile(r"(?P\d),(?P\d),(?P\d)") m = re.match(p, s) m > <_sre.SRE_Match object at 0x011BE610> print m.groups() > ('1', '2', '3') > > Is it possible to call the group names, so that I can i

Re: Geohashing

2009-04-29 Thread djc
py", line 1228, in __run compileflags, 1) in test.globs File "", line 1 geohash(37.421542, -122.085589, b'2005-05-26-10458.68') ^ SyntaxError: invalid syntax ** 1 items had failures: 1 of 1 in __main__.geohash ***Test Failed*** 1 failures. (1, 1) >>> -- djc @work -- http://mail.python.org/mailman/listinfo/python-list

Re: simple way to un-nest (flatten?) list

2006-11-07 Thread djc
;x':['test','alt','3rd'],'y':'single'} r1 ['ASLIB', 'Aslib', 'test', 'alt', '3rd', 'JDOC', 'jdoc', 's', 'i', 'n', 'g', 'l', 'e'] r2 set(['Aslib', 'JDOC', 'g', '3rd', 'i', 'l', 'n', 'ASLIB', 's', 'test', 'jdoc', 'alt', 'e']) r4 = sum(d.values(), []) TypeError: can only concatenate list (not "str") to list -- djc -- http://mail.python.org/mailman/listinfo/python-list

Re: simple way to un-nest (flatten?) list

2006-11-06 Thread djc
keys = r.keys() > keys.sort() > result = [] > for key in keys: > result.extend(r[key]) > result = tuple(result) Thank you everybody. As it is possible that the tuples will not always be the same word in variant cases result = sum(r.values(), ()) will do fine and is as simple as I suspected the answer would be. -- djc -- http://mail.python.org/mailman/listinfo/python-list

simple way to un-nest (flatten?) list

2006-11-05 Thread djc
in table if line[7] in ('JDOC','jdoc','Aslib','ASLIB')] so how should I get from {'a':('ASLIB','Aslib'),'j':('JDOC','jdoc')} to ('Aslib','ASLIB','JDOC','jdoc') -- djc -- http://mail.python.org/mailman/listinfo/python-list