Re: Find duplicates in a list and count them ...

2009-03-26 Thread Albert Hopkins
On Thu, 2009-03-26 at 12:22 -0700, paul.scipi...@aps.com wrote: > Hello, > > I'm a newbie to Python. I have a list which contains integers (about > 80,000). I want to find a quick way to get the numbers that occur in > the list more than once, and how many times that number is duplicated > in t

Re: Find duplicates in a list and count them ...

2009-03-26 Thread D'Arcy J.M. Cain
python that can grab this info without > looping through a list. icount = {} for i in list_of_ints: icount[i] = icount.get(i, 0) + 1 Now you have a dictionary of every integer in the list and the count of times it appears. -- D'Arcy J.M. Cain | Democracy is

Find duplicates in a list and count them ...

2009-03-26 Thread Paul . Scipione
Hello, I'm a newbie to Python. I have a list which contains integers (about 80,000). I want to find a quick way to get the numbers that occur in the list more than once, and how many times that number is duplicated in the list. I've done this right now by looping through the list, getting a

Re: How do I count the distance between strings in a list?

2009-02-27 Thread Ken Seehart
collin wrote: For example, if I were to have the code randomlist = ["1", "2", "3", "4"] And I want to count the distance between strings "1" and "4" which is 3, what command can I use to do this? -- http://mail.pyth

Re: How do I count the distance between strings in a list?

2009-02-23 Thread Steven D'Aprano
On Mon, 23 Feb 2009 21:35:21 -0800, collin wrote: > For example, if I were to have the code > > randomlist = ["1", "2", "3", "4"] > > And I want to count the distance between strings "1" and "4" which is 3, > what com

Re: How do I count the distance between strings in a list?

2009-02-23 Thread Jonathan Gardner
On Feb 23, 9:35 pm, collin wrote: > For example, if I were to have the code > > randomlist = ["1", "2", "3", "4"] > > And I want to count the distance between strings "1" and "4" which is > 3, what command can I use

How do I count the distance between strings in a list?

2009-02-23 Thread collin
For example, if I were to have the code randomlist = ["1", "2", "3", "4"] And I want to count the distance between strings "1" and "4" which is 3, what command can I use to do this? -- http://mail.python.org/mailman/listinfo/python-list

Re: count secton of data in list

2009-02-23 Thread S Arrowsmith
In article <3ed253bb-d6ec-4f47-af08-ad193e9c4...@h16g2000yqj.googlegroups.com>, odeits wrote: >def count_consecutive(rows): >switch =3D 0 >count =3D 0 >for r in rows: >if r[-1] =3D=3D switch: >count +=3D 1 >else: >

Re: count secton of data in list

2009-02-21 Thread odeits
1r[2],switch > >                data2_row.append([d1r[0],d1r[1],d1r[2],switch]) > > HTH, > > Emile def count_consecutive(rows): switch = 0 count = 0 for r in rows: if r[-1] == switch: count += 1 else: switch = not switch

Re: count secton of data in list

2009-02-20 Thread Emile van Sebille
brianrpsgt1 wrote: def step1(val): data2_row = [] for d1r in data1_row: if d1r[1] >= val: switch = 0 data2_row = d1r[0],d1r[1],d1r[2],switch data2_row.append([d1r[0],d1r[1],d1r[2],switch]) HTH, Emile -- http://mail.python.org/mailma

count secton of data in list

2009-02-20 Thread brianrpsgt1
I have a list of three columns of data. I run the following code: def step1(val): for d1r in data1_row: if d1r[1] >= val: switch = 0 data2_row = d1r[0],d1r[1],d1r[2],switch print d1r[0],d1r[1],d1r[2],switch else: switch = 1

Re: creating a pattern using a previous match and a count of the number of '('s in it

2009-01-27 Thread MRAB
upto_1st_closed_parenth[i].count('(') #expand the pattern to get all of the prototype #ie upto the last closed parenthesis #saying something like pattern = re.compile(\ 'match_upto_1st_closed_parenth[i]+\

creating a pattern using a previous match and a count of the number of '('s in it

2009-01-27 Thread me
ompile('\w+::\w+\([^)]*\)') match_upto_1st_closed_parenth= re.findall(pattern_upto_1st_closed_parenth,txt) num_of_protos = len(match_upto_1st_closed_parenth) for i in range (0,num_of_protos-1): num_of_open_parenths = match_upto_1st_closed_parenth[i].count('(') #expand the

Re: efficient Python object count

2008-11-07 Thread darrenr
> Here you > are:http://svn.python.org/projects/python/branches/release25-maint/Misc/S... Excellent, thank you. -- http://mail.python.org/mailman/listinfo/python-list

Re: efficient Python object count

2008-11-07 Thread Christian Heimes
darrenr wrote: Thanks for the quick reply. Could you provide a link to more information on the debug build you refer to? Here you are: http://svn.python.org/projects/python/branches/release25-maint/Misc/SpecialBuilds.txt -- http://mail.python.org/mailman/listinfo/python-list

Re: efficient Python object count

2008-11-07 Thread robert
darrenr wrote: Thanks for the quick reply. Could you provide a link to more information on the debug build you refer to? A modified version of this algorithm should do the trick for my purposes, it finds the non-containers that gc ignores. I don't care how long it takes to compute, I just don't

Re: efficient Python object count

2008-11-07 Thread darrenr
> Thanks for the quick reply. Could you provide a link to more > information on the debug build you refer to? A modified version of this algorithm should do the trick for my purposes, it finds the non-containers that gc ignores. I don't care how long it takes to compute, I just don't want the proc

Re: efficient Python object count

2008-11-06 Thread darrenr
On Nov 6, 7:28 pm, Christian Heimes <[EMAIL PROTECTED]> wrote: > darrenr wrote: > > Hello, > > > Does anyone know of an efficient way to get a count of the total > > number of Python objects in CPython? The best solution I've been able > > to find is len(

Re: efficient Python object count

2008-11-06 Thread Christian Heimes
darrenr wrote: Hello, Does anyone know of an efficient way to get a count of the total number of Python objects in CPython? The best solution I've been able to find is len(gc.get_objects()) which unfortunately has to walk a C linked list *and* creates a list containing all of the objects,

efficient Python object count

2008-11-06 Thread darrenr
Hello, Does anyone know of an efficient way to get a count of the total number of Python objects in CPython? The best solution I've been able to find is len(gc.get_objects()) which unfortunately has to walk a C linked list *and* creates a list containing all of the objects, when all I need

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread M.-A. Lemburg
On 2008-10-23 09:26, Gilles Ganault wrote: > On Thu, 23 Oct 2008 00:24:01 -0200, "Gabriel Genellina" > <[EMAIL PROTECTED]> wrote: >> In case you didn't notice, B.D. already provided the answer you're after - >> reread his 3rd paragraph from the end. > > Yes, but it doesn't work with this wrapper

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Gerhard Häring
(APSW version 3.5.9-r1): The recommended way is to pass the arguments to cursor.execute, ie: I'm getting an error when doing it this way: === isbn = "123" sql = "SELECT COUNT(*) FROM books WHERE isbn='%s'" #Incorrect number of bindings supplied. The cur

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Gerhard Häring
Dennis Lee Bieber wrote: On Thu, 23 Oct 2008 09:26:54 +0200, Gilles Ganault <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: Yes, but it doesn't work with this wrapper (APSW version 3.5.9-r1): APSW is not, so far as I recall, a "DB-API 2" adapter -- it is a touch more

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Bruno Desthuilliers
wrapper (APSW version 3.5.9-r1): The recommended way is to pass the arguments to cursor.execute, ie: I'm getting an error when doing it this way: === isbn = "123" sql = "SELECT COUNT(*) FROM books WHERE isbn='%s'" #Incorrect number of bindings supplied. The

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Tino Wildenhain
Gilles Ganault wrote: Hello I'm trying to use the APSW package to access a SQLite database, but can't find how to check if a row exists. I just to read a tab-separated file, extract a key/value from each line, run "SELECT COUNT(*)" to check whether this tuple exists in the

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-23 Thread Gilles Ganault
3.5.9-r1): >> The recommended way is to pass the arguments to cursor.execute, ie: I'm getting an error when doing it this way: === isbn = "123" sql = "SELECT COUNT(*) FROM books WHERE isbn='%s'" #Incorrect number of bindings supplied. The current stat

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-22 Thread Gabriel Genellina
api specification, the return value of cursor.execute is not defined (IOW : can be absolutely anything). OK, I'll check if I can find how to get the result from a SELECT COUNT(*) and if not, use a different wrapper. Thanks a lot for the embedded comments. In case you didn't notice

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-22 Thread Cousin Stanley
> > Now I don't know what apsw is, but it's common for libraries > to provide their own wrapping of the db-api. > From the Debian GNU/Linux package manager APSW (Another Python SQLite Wrapper) is an SQLite 3 wrapper that provides the thinnest layer over SQLite 3 possi

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-22 Thread Gilles Ganault
: can be absolutely >anything). OK, I'll check if I can find how to get the result from a SELECT COUNT(*) and if not, use a different wrapper. Thanks a lot for the embedded comments. -- http://mail.python.org/mailman/listinfo/python-list

Re: [APSW] SELECT COUNT(*) not succesfull?

2008-10-22 Thread Bruno Desthuilliers
Gilles Ganault a écrit : Hello I'm trying to use the APSW package to access a SQLite database, but can't find how to check if a row exists. I just to read a tab-separated file, extract a key/value from each line, run "SELECT COUNT(*)" to check whether this tuple exists in

[APSW] SELECT COUNT(*) not succesfull?

2008-10-22 Thread Gilles Ganault
Hello I'm trying to use the APSW package to access a SQLite database, but can't find how to check if a row exists. I just to read a tab-separated file, extract a key/value from each line, run "SELECT COUNT(*)" to check whether this tuple exists in the SQLite database, and i

Re: Win32.client, DAO.DBEngine and exceeding the file sharing count lock

2008-07-03 Thread Iain King
On Jul 2, 8:13 pm, Tim Golden <[EMAIL PROTECTED]> wrote: > In case it helps, there's a recipe just shown up > on the Python Cookbook which at least illustrates > DAO use: > > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/572165 > > TJG On Jul 2, 6:30 pm, "M.-A. Lemburg" <[EMAIL PROTECTED

Re: Win32.client, DAO.DBEngine and exceeding the file sharing count lock

2008-07-02 Thread Tim Golden
In case it helps, there's a recipe just shown up on the Python Cookbook which at least illustrates DAO use: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/572165 TJG -- http://mail.python.org/mailman/listinfo/python-list

Re: Win32.client, DAO.DBEngine and exceeding the file sharing count lock

2008-07-02 Thread M.-A. Lemburg
On 2008-07-02 16:54, Iain King wrote: On Jul 2, 3:29 pm, Tim Golden <[EMAIL PROTECTED]> wrote: Iain King wrote: Hi. I'm using the win32 module to access an Access database, but I'm running into the File Sharing lock count as inhttp://support.microsoft.com/kb/815281 The solu

Re: Win32.client, DAO.DBEngine and exceeding the file sharing count lock

2008-07-02 Thread Tim Golden
Iain King wrote: On Jul 2, 3:29 pm, Tim Golden <[EMAIL PROTECTED]> wrote: Iain King wrote: Hi. I'm using the win32 module to access an Access database, but I'm running into the File Sharing lock count as inhttp://support.microsoft.com/kb/815281 The solution I'd like to

Re: Win32.client, DAO.DBEngine and exceeding the file sharing count lock

2008-07-02 Thread Iain King
On Jul 2, 3:29 pm, Tim Golden <[EMAIL PROTECTED]> wrote: > Iain King wrote: > > Hi.  I'm using the win32 module to access an Access database, but I'm > > running into the File Sharing lock count as > > inhttp://support.microsoft.com/kb/815281 > > The so

Re: Win32.client, DAO.DBEngine and exceeding the file sharing count lock

2008-07-02 Thread Tim Golden
Iain King wrote: Hi. I'm using the win32 module to access an Access database, but I'm running into the File Sharing lock count as in http://support.microsoft.com/kb/815281 The solution I'd like to use is the one where you can temporarily override the setting using (i

Win32.client, DAO.DBEngine and exceeding the file sharing count lock

2008-07-02 Thread Iain King
Hi. I'm using the win32 module to access an Access database, but I'm running into the File Sharing lock count as in http://support.microsoft.com/kb/815281 The solution I'd like to use is the one where you can temporarily override the setting using (if we were in VB): DAO.DBE

Re: Decrementing of reference count of new objects?

2008-04-01 Thread Gabriel Genellina
En Tue, 01 Apr 2008 18:49:28 -0300, Mitko Haralanov <[EMAIL PROTECTED]> escribió: > For the most part, I understand the theory behind reference counting in > Python C code. But there is one thing that I am confused about and I > have not been able to clear it up. > > Let say that you have the fo

Decrementing of reference count of new objects?

2008-04-01 Thread Mitko Haralanov
For the most part, I understand the theory behind reference counting in Python C code. But there is one thing that I am confused about and I have not been able to clear it up. Let say that you have the following function (over-simplified): PyObject *do_work (PyObject *self, PyObject *args) {

Re: frequency count or number of occurences of a number in an array

2008-03-13 Thread Bernard
d'oh! On 12 mar, 07:58, John Machin <[EMAIL PROTECTED]> wrote: > On Mar 12, 10:29 pm, Bernard <[EMAIL PROTECTED]> wrote: > > > > > Hey Larry, > > > that one is fairly easy: > > > >>> from array import array > > >>> array

Re: frequency count or number of occurences of a number in an array

2008-03-12 Thread Larry
Thanks to all those who replied to this post. I'm gonna try your suggestions. They are a great help. -- http://mail.python.org/mailman/listinfo/python-list

Re: frequency count or number of occurences of a number in an array

2008-03-12 Thread John Machin
On Mar 12, 10:29 pm, Bernard <[EMAIL PROTECTED]> wrote: > Hey Larry, > > that one is fairly easy: > > >>> from array import array > >>> array('i', [1, 2, 3, 4, 5, 1, 2]) > >>> def count(x, arr): > > cpt = 0 # declare

Re: frequency count or number of occurences of a number in an array

2008-03-12 Thread Bernard
Hey Larry, that one is fairly easy: >>> from array import array >>> array('i', [1, 2, 3, 4, 5, 1, 2]) >>> def count(x, arr): cpt = 0 # declare a counter variable for el in arr: # for each element in the array if el == x

Re: frequency count or number of occurences of a number in an array

2008-03-12 Thread Paul Hankin
On Mar 12, 10:26 am, Larry <[EMAIL PROTECTED]> wrote: > I'm new to Python. I have a file (an image file actually) that I need > to read pixel by pixel. It's an 8-bit integer type. I need to get the > statistics like mean, standard deviation, etc., which I know a little > bit already from reading nu

frequency count or number of occurences of a number in an array

2008-03-12 Thread Larry
Dear all, I'm new to Python. I have a file (an image file actually) that I need to read pixel by pixel. It's an 8-bit integer type. I need to get the statistics like mean, standard deviation, etc., which I know a little bit already from reading numpy module. What I want to know is how to get the n

Re: mysqldb SELECT COUNT reurns 1

2008-01-09 Thread mike
On Dec 27 2007, 5:25 pm, Ian Clark <[EMAIL PROTECTED]> wrote: > On 2007-12-27, SMALLp <[EMAIL PROTECTED]> wrote: > > > connectionString = {"host":"localhost", "user":"root", > > "passwd":"pofuck", "db":"fileshare"} > > dataTable = "files" > > conn = mysql.connect(host=connectionString["host"], > >

Re: mysqldb SELECT COUNT reurns 1

2007-12-27 Thread Ian Clark
On 2007-12-27, SMALLp <[EMAIL PROTECTED]> wrote: > connectionString = {"host":"localhost", "user":"root", > "passwd":"pofuck", "db":"fileshare"} > dataTable = "files" > conn = mysql.connect(host=connectionString["host"], > user=connectionString["user"], passwd=connectionString["passwd"], > db=conn

Re: mysqldb SELECT COUNT reurns 1

2007-12-27 Thread John Machin
uot;:"pofuck", "db":"fileshare"} > dataTable = "files" > conn = mysql.connect(host=connectionString["host"], > user=connectionString["user"], passwd=connectionString["passwd"], > db=connectionString["db"]) > > curso

Re: mysqldb SELECT COUNT reurns 1

2007-12-27 Thread SMALLp
Rob Williscroft wrote: > SMALLp wrote in news:[EMAIL PROTECTED] in comp.lang.python: > >> Hy! I nave another problem I can't solve! >> >> >> import MySQLdb as mysql > >> cursor = conn.cursor() >> sql = "SELECT COUNT(*) FROM " +

Re: mysqldb SELECT COUNT reurns 1

2007-12-27 Thread Rob Williscroft
SMALLp wrote in news:[EMAIL PROTECTED] in comp.lang.python: > Hy! I nave another problem I can't solve! > > > import MySQLdb as mysql > cursor = conn.cursor() > sql = "SELECT COUNT(*) FROM " + dataTable > res = cursor.execute(sql) I think you n

mysqldb SELECT COUNT reurns 1

2007-12-27 Thread SMALLp
l.connect(host=connectionString["host"], user=connectionString["user"], passwd=connectionString["passwd"], db=connectionString["db"]) cursor = conn.cursor() sql = "SELECT COUNT(*) FROM " + dataTable res = cursor.execute(sql) pr

Re: Compressing a text file using count of continous characters

2007-12-15 Thread makkalot
> > > XYZDEFAAcdAA --> XYZ8ADEF2Acd2A > (RLE), that saved a lot of googles I have written a rle in my first years in school. It compresses a bitmap image %50 compression is achivied :) The link : http://arilaripi.org/index.php?option=com_remository&Itemid=26&func=fileinfo&id=273 And i

Re: Compressing a text file using count of continous characters

2007-12-14 Thread nirvana
On Dec 14, 12:07 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On Dec 14, 2007 10:54 AM, nirvana <[EMAIL PROTECTED]> wrote: > > > I need to count the number of continous character occurances(more than > > 1) in a file, and replace it with a compressed vers

Re: Compressing a text file using count of continous characters

2007-12-14 Thread Chris Mellon
On Dec 14, 2007 10:54 AM, nirvana <[EMAIL PROTECTED]> wrote: > I need to count the number of continous character occurances(more than > 1) in a file, and replace it with a compressed version, like below > XYZDEFAAcdAA --> XYZ8ADEF2Acd2A > This sounds like homework.

Re: Compressing a text file using count of continous characters

2007-12-14 Thread Marc 'BlackJack' Rintsch
On Fri, 14 Dec 2007 08:54:58 -0800, nirvana wrote: > I need to count the number of continous character occurances(more than > 1) in a file, and replace it with a compressed version, like below > XYZDEFAAcdAA --> XYZ8ADEF2Acd2A Great. Then go ahead an

Compressing a text file using count of continous characters

2007-12-14 Thread nirvana
I need to count the number of continous character occurances(more than 1) in a file, and replace it with a compressed version, like below XYZDEFAAcdAA --> XYZ8ADEF2Acd2A Thanks Sumod -- http://mail.python.org/mailman/listinfo/python-list

Re: count pages in a pdf

2007-11-27 Thread Jon Ribbens
On 2007-11-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > is it possible to parse a pdf file in python? for starters, i would > like to count the number of pages in a pdf file. i see there is a > project called ReportLab, but it seems to be a pdf generator... i > can&#x

Re: count pages in a pdf

2007-11-27 Thread Andreas Lobinger
Tim Golden wrote: > [EMAIL PROTECTED] wrote: > >> is it possible to parse a pdf file in python? for starters, i would >> like to count the number of pages in a pdf file. i see there is a >> project called ReportLab, but it seems to be a pdf generator... i >> ca

Re: count pages in a pdf

2007-11-27 Thread Tim Golden
[EMAIL PROTECTED] wrote: > is it possible to parse a pdf file in python? for starters, i would > like to count the number of pages in a pdf file. i see there is a > project called ReportLab, but it seems to be a pdf generator... i > can't tell if i would be able to

count pages in a pdf

2007-11-27 Thread belred
is it possible to parse a pdf file in python? for starters, i would like to count the number of pages in a pdf file. i see there is a project called ReportLab, but it seems to be a pdf generator... i can't tell if i would be able to parse a pdf file programmically. thanks fo

Re: count increment...

2007-11-02 Thread Hendrik van Rooyen
Beema shafreen wrote: 8< --- file >my script: > >#!/usr/bin/env python > > >fh = open('complete_span','r') >line = fh.readline().split('#') >old_probe = line[0].strip() >old_value = line[1].strip()

count increment...

2007-11-02 Thread Beema shafreen
= open('complete_span','r') line = fh.readline().split('#') old_probe = line[0].strip() old_value = line[1].strip() print old_probe, old_value count = 1 line = "" while line: line = fh.readline().strip() if line : current_pr

Re: delineating by comma where commas inside quotation marks don't count

2007-10-26 Thread Junior
"Dan Bishop" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Oct 24, 8:56 pm, "Junior" <[EMAIL PROTECTED]> wrote: >> I want to open a text file for reading and delineate it by comma. I also >> want any data >> surrounded by

Re: delineating by comma where commas inside quotation marks don't count

2007-10-25 Thread Travis Brady
On 10/24/07, Dan Bishop <[EMAIL PROTECTED]> wrote: > > On Oct 24, 8:56 pm, "Junior" <[EMAIL PROTECTED]> wrote: > > I want to open a text file for reading and delineate it by comma. I > also > > want any data > > surrounded by quotation marks th

Re: delineating by comma where commas inside quotation marks don't count

2007-10-24 Thread equand
On Oct 25, 3:56 am, "Junior" <[EMAIL PROTECTED]> wrote: > I want to open a text file for reading and delineate it by comma. I also > want any data > surrounded by quotation marks that has a comma in it, not to count the > commas inside the > quotation marks > &

Re: delineating by comma where commas inside quotation marks don't count

2007-10-24 Thread Dan Bishop
On Oct 24, 8:56 pm, "Junior" <[EMAIL PROTECTED]> wrote: > I want to open a text file for reading and delineate it by comma. I also > want any data > surrounded by quotation marks that has a comma in it, not to count the > commas inside the > quotation marks

delineating by comma where commas inside quotation marks don't count

2007-10-24 Thread Junior
I want to open a text file for reading and delineate it by comma. I also want any data surrounded by quotation marks that has a comma in it, not to count the commas inside the quotation marks if the file testfile.txt contains the following; 5,Tuesday,"May is a spring month",Fath

easiest way to count memory eaten by call to Python func?

2007-06-07 Thread dmitrey
hi all, which way is the simplest for now to obtain the memory amount eaten by call to Python 'myfunc' function? Thx, D -- http://mail.python.org/mailman/listinfo/python-list

Re: how do I count spaces at the beginning of a string?

2007-05-17 Thread Steven Howe
Paul McGuire wrote: On May 16, 9:02 pm, walterbyrd <[EMAIL PROTECTED]> wrote: The strings start with whitespace, and have a '*' or an alphanumeric character. I need to know how many whitespace characters exist at the beginning of the string. using buitlin function len() and lstrip() a

Re: how do I count spaces at the beginning of a string?

2007-05-17 Thread Paul McGuire
This really is a pretty basic question - to most folks on this list, it's about the same as "how do I count the fingers on my hand?". Is this your first Python program? Homework assignment? First program ever written in any language? Try reading one of the online tutorials or pic

Re: How do I count the number of spaces at the left end of a string?

2007-05-16 Thread Asun Friere
On May 17, 8:18 am, Steven Howe <[EMAIL PROTECTED]> wrote: > walterbyrd wrote: > > I don't know exactly what the first non-space character is. I know the > > first non-space character will be * or an alphanumeric character. > > using builtin function rindex But only if there is a guarantee that a

Re: how do I count spaces at the beginning of a string?

2007-05-16 Thread Anthony Irwin
and just really learning but this is what I came up > with. > > #!/usr/bin/env python > > def main(): > s = " abc def ghi" > count = 0 > > for i in s: > if i == ' ': > count += 1 > else: >

Re: how do I count spaces at the beginning of a string?

2007-05-16 Thread Norman Lorrain
On 2007-05-16 20:02:18 -0600, walterbyrd <[EMAIL PROTECTED]> said: > The strings start with whitespace, and have a '*' or an alphanumeric > character. I need to know how many whitespace characters exist at the > beginning of the string. a = ' three spaces' print len(a) -len(a.lstrip()) -- http

Re: how do I count spaces at the beginning of a string?

2007-05-16 Thread Steven Bethard
walterbyrd wrote: > The strings start with whitespace, and have a '*' or an alphanumeric > character. I need to know how many whitespace characters exist at the > beginning of the string. You really need to stop posting the same message multiple times. A possible answer using regular expressions:

Re: how do I count spaces at the beginning of a string?

2007-05-16 Thread Anthony Irwin
#!/usr/bin/env python def main(): s = " abc def ghi" count = 0 for i in s: if i == ' ': count += 1 else: break print count if __name__ == '__main__': main() -- Kind Regard

how do I count spaces at the beginning of a string?

2007-05-16 Thread walterbyrd
The strings start with whitespace, and have a '*' or an alphanumeric character. I need to know how many whitespace characters exist at the beginning of the string. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I count the number of spaces at the left end of a string?

2007-05-16 Thread Steven Howe
walterbyrd wrote: > I don't know exactly what the first non-space character is. I know the > first non-space character will be * or an alphanumeric character. > > using builtin function rindex st = 'asblde ' >>> st.rindex(' ') sph -- HEX: 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0

Re: How do I count the number of spaces at the left end of a string?

2007-05-16 Thread James Stroud
walterbyrd wrote: > I don't know exactly what the first non-space character is. I know the > first non-space character will be * or an alphanumeric character. > This is another of the hundreds of ways: py> for i,c in enumerate(astring): ... if c != ' ': break ... py> print i -- http://mail.p

Re: How do I count the number of spaces at the left end of a string?

2007-05-16 Thread Daniel Nogradi
> I don't know exactly what the first non-space character is. I know the > first non-space character will be * or an alphanumeric character. How about: >>> mystring = 'ksjfkfjkfjds ' >>> print len( mystring ) - len( mystring.lstrip( ) ) 4 HTH, Daniel -- http://mail.python.org/mailman/li

How do I count the number of spaces at the left end of a string?

2007-05-16 Thread walterbyrd
I don't know exactly what the first non-space character is. I know the first non-space character will be * or an alphanumeric character. -- http://mail.python.org/mailman/listinfo/python-list

Mysterious argument count error to __new__

2007-04-10 Thread Clarence
I'm having problems with JPype and am trying to change the way it creates Python classes as proxies for Java classes and interfaces. I'm trying to get around "inconsistent mro" problems, but in doing so, I've run into a real mystery. Here's the original code. It first makes a metaclass, then makes

Re: To count number of quadruplets with sum = 0

2007-03-26 Thread mark . dufour
> FWIW, the original program can also be compiled with Shed Skin (http:// > mark.dufour.googlepages.com), an experimental (static-)Python-to-C++ > compiler, resulting in a speedup of about 8 times for a single test > with 500 tuples. here's a slightly modified version that works with > Shed Skin C

Re: To count number of quadruplets with sum = 0

2007-03-18 Thread Jorge Godoy
"n00m" <[EMAIL PROTECTED]> writes: > my dial-up line's too slow for downloading 4mb of shedskin-0.0.20.exe Don't worry! We can email it to you. :-D -- Jorge Godoy <[EMAIL PROTECTED]> -- http://mail.python.org/mailman/listinfo/python-list

Re: To count number of quadruplets with sum = 0

2007-03-17 Thread n00m
>>> RESTART === >>> 0 30.4740708665 secs (Anton Vredegoor) >>> RESTART === >>> 0 30.4132625795 secs (Anton Vredegoor) >>> RESTART === >>> 0 30.4812175849 secs (Anton Vredegoor) >>> +

Re: To count number of quadruplets with sum = 0

2007-03-17 Thread n00m
my dial-up line's too slow for downloading 4mb of shedskin-0.0.20.exe -- http://mail.python.org/mailman/listinfo/python-list

Re: To count number of quadruplets with sum = 0

2007-03-17 Thread n00m
bearophileH! I gave to your "oil" svrl runs ("z in dict" instd of "dict.has_key" saved only ~0.4 sec). The result is (and I'm completely lost in all these *optimizations* :)): >>> RESTART === >>> 0 34.78 secs (bearophileH) >>> RES

Re: To count number of quadruplets with sum = 0

2007-03-17 Thread bearophileHUGS
Mark Dufour: > FWIW, the original program can also be compiled with Shed Skin (http:// > mark.dufour.googlepages.com), an experimental (static-)Python-to-C++ > compiler, resulting in a speedup of about 8 times for a single test > with 500 tuples. If we want to play, then this is a literal translat

Re: To count number of quadruplets with sum = 0

2007-03-17 Thread mark . dufour
Paul Rubin wrote: > "n00m" <[EMAIL PROTECTED]> writes: > > Two first outputs is of above (your) code; next two - of my code: > > Yeah, I see now that we both used the same algorithm. At first glance > I thought you had done something much slower. The 10 second limit > they gave looks like they i

Re: To count number of quadruplets with sum = 0

2007-03-17 Thread Paul Rubin
[EMAIL PROTECTED] writes: > for x in e: > for y in r: > if -x-y in h: > sch += h[-x-y] I wonder whether g = h.get for x in e: for y in r: if -x-y in h: sch += g(-x-y, 0) might be a little bit faster. Also, -x-y

Re: To count number of quadruplets with sum = 0

2007-03-17 Thread bearophileHUGS
n00m: > i have no NumPy to test it... > without Psyco Anton's code is the winner: ~48sec vs ~58sec of my code > But with Psyco my runtime is ~28sec; Anton's - ~30sec (PC: 1.6 ghz, > 512 mb) > Not so bad.. keeping in mind that 256000 billions quadruplets to > check :) I have oiled it a bit, you can

Re: To count number of quadruplets with sum = 0

2007-03-17 Thread n00m
i have no NumPy to test it... without Psyco Anton's code is the winner: ~48sec vs ~58sec of my code But with Psyco my runtime is ~28sec; Anton's - ~30sec (PC: 1.6 ghz, 512 mb) Not so bad.. keeping in mind that 256000 billions quadruplets to check :) import psyco, time psyco.full() t = time.clock(

Re: To count number of quadruplets with sum = 0

2007-03-16 Thread marek . rocki
, dl cdl = numpy.sort(-(cle + dle)) del cle, dle # Iterate over arrays, count matching elements result = 0 i, j = 0, 0 n = n*n try: while True: while abl[i] < cdl[j]: i +

Re: To count number of quadruplets with sum = 0

2007-03-16 Thread Paul Rubin
Steven Bethard <[EMAIL PROTECTED]> writes: > > According to a post by Raymond Hettinger it's faster to use that > > iterator instead of `int`. > Yep. It's because the .next() method takes no arguments, while int() > takes varargs because you can do:: ... Heh, good point. Might be worth putting a

Re: To count number of quadruplets with sum = 0

2007-03-16 Thread Steven Bethard
Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, Paul Rubin wrote: > >> "n00m" <[EMAIL PROTECTED]> writes: >>> h = collections.defaultdict(itertools.repeat(0).next) >> Something wrong with >>h = collections.defaultdict(int) >> ? > > According to a post by Raymond Hettinger it's

Re: To count number of quadruplets with sum = 0

2007-03-16 Thread Anton Vredegoor
n00m wrote: > 62.5030784639 Maybe this one could save a few seconds, it works best when there are multiple occurrences of the same value. A. from time import time def freq(L): D = {} for x in L: D[x] = D.get(x,0)+1 return D def test(): t = time() f = fil

Re: To count number of quadruplets with sum = 0

2007-03-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Paul Rubin wrote: > "n00m" <[EMAIL PROTECTED]> writes: >> h = collections.defaultdict(itertools.repeat(0).next) > > Something wrong with >h = collections.defaultdict(int) > ? According to a post by Raymond Hettinger it's faster to use that iterator instead of `in

Re: To count number of quadruplets with sum = 0

2007-03-16 Thread Paul McGuire
On Mar 16, 12:49 am, "n00m" <[EMAIL PROTECTED]> wrote: > for o in range(int(f.readline())): > row = map(int, f.readline().split()) > q.append(row[0]) > w.append(row[1]) > e.append(row[2]) > r.append(row[3]) Does this help at all in reading in your data? numlines = f.readline() rows = [

Re: To count number of quadruplets with sum = 0

2007-03-15 Thread Paul Rubin
"n00m" <[EMAIL PROTECTED]> writes: > http://rapidshare.com/files/21267938/m1000.txt > http://rapidshare.com/files/21268386/m4000.txt I get 33190970 for the first set and 0 for the second set. The first set only makes 38853 distinct dictionary entries, I guess because the numbers are all fairly sm

Re: To count number of quadruplets with sum = 0

2007-03-15 Thread n00m
For those who interested, my test input files: http://rapidshare.com/files/21267938/m1000.txt http://rapidshare.com/files/21268386/m4000.txt -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   >