Re: Counting Python threads vs C/C++ threads

2019-07-21 Thread Peter J. Holzer
On 2019-07-16 12:48:33 -0700, Dan Stromberg wrote: > On Tue, Jul 16, 2019 at 11:13 AM Barry Scott wrote: > > Does top show the process using 100% CPU? > > > Nope. CPU utilization and disk use are both low. > > We've been going into top, and then hitting '1' to see things broken down > by CPU cor

Re: Counting Python threads vs C/C++ threads

2019-07-17 Thread Thomas Jollans
On 17/07/2019 09.58, Barry Scott wrote: > >> On 16 Jul 2019, at 20:48, Dan Stromberg wrote: >> >> >> >> A question arises though: Does threading.active_count() only show Python >> threads created with the threading module? What about threads created with >> the thread module? > Only pythons t

Re: Counting Python threads vs C/C++ threads

2019-07-17 Thread Barry Scott
> On 16 Jul 2019, at 20:48, Dan Stromberg wrote: > > > > On Tue, Jul 16, 2019 at 11:13 AM Barry Scott > wrote: > I'm going to assume you are on linux. > Yes, I am. Ubuntu 16.04.6 LTS sometimes, Mint 19.1 other times. > > On 16 Jul 2019, at 18:35, Dan Strombe

Re: Counting Python threads vs C/C++ threads

2019-07-16 Thread Dan Stromberg
On Tue, Jul 16, 2019 at 11:13 AM Barry Scott wrote: > I'm going to assume you are on linux. > Yes, I am. Ubuntu 16.04.6 LTS sometimes, Mint 19.1 other times. On 16 Jul 2019, at 18:35, Dan Stromberg wrote: > > > > I'm looking at a performance problem in a large CPython 2.x/3.x codebase > > with

Re: Counting Python threads vs C/C++ threads

2019-07-16 Thread Barry Scott
I'm going to assume you are on linux. On 16 Jul 2019, at 18:35, Dan Stromberg wrote: > > I'm looking at a performance problem in a large CPython 2.x/3.x codebase > with quite a few dependencies. > > I'm not sure what's causing the slowness yet. The CPU isn't getting hit > hard, and I/O on the

Re: Counting words in a string??

2016-09-30 Thread breamoreboy
On Friday, September 30, 2016 at 8:12:47 PM UTC+1, Jake wrote: > On Friday, 30 September 2016 19:49:57 UTC+1, srinivas devaki wrote: > > On Oct 1, 2016 12:10 AM, "Jake" wrote: > > > > > > Hi, I need a program which: > > > 1) Asks the user for a sentence of their choice (not including > > punctuati

Re: Counting words in a string??

2016-09-30 Thread mm0fmf
On 30/09/2016 20:12, Jake wrote: On Friday, 30 September 2016 19:49:57 UTC+1, srinivas devaki wrote: On Oct 1, 2016 12:10 AM, "Jake" wrote: Hi, I need a program which: 1) Asks the user for a sentence of their choice (not including punctuation) 2) Ask the user which word they would like to

Re: Counting words in a string??

2016-09-30 Thread Chris Angelico
On Sat, Oct 1, 2016 at 5:12 AM, Jake wrote: > Could you make the program for me or provide an outline? No. In case you didn't read any of the other responses, this community is not a plagiarism source. If you want to learn to be a programmer, you're going to have to learn some key skills, one of

Re: Counting words in a string??

2016-09-30 Thread Peter Pearson
On Fri, 30 Sep 2016 11:37:19 -0700 (PDT), Jake wrote: > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they c

Re: Counting words in a string??

2016-09-30 Thread Jake
On Friday, 30 September 2016 19:49:57 UTC+1, srinivas devaki wrote: > On Oct 1, 2016 12:10 AM, "Jake" wrote: > > > > Hi, I need a program which: > > 1) Asks the user for a sentence of their choice (not including > punctuation) > > 2) Ask the user which word they would like to know is repeated > >

Re: Counting words in a string??

2016-09-30 Thread Rob Gaddi
Jake wrote: > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they chose > from their sentence. > > It would

Re: Counting words in a string??

2016-09-30 Thread srinivas devaki
On Oct 1, 2016 12:10 AM, "Jake" wrote: > > Hi, I need a program which: > 1) Asks the user for a sentence of their choice (not including punctuation) > 2) Ask the user which word they would like to know is repeated > 3) Print out to the user how many times the word came up which they chose from the

Re: counting unique numpy subarrays

2015-12-04 Thread duncan smith
On 04/12/15 23:06, Peter Otten wrote: > duncan smith wrote: > >> Hello, >> I'm trying to find a computationally efficient way of identifying >> unique subarrays, counting them and returning an array containing only >> the unique subarrays and a corresponding 1D array of counts. The >> follow

Re: counting unique numpy subarrays

2015-12-04 Thread duncan smith
On 04/12/15 22:36, Albert-Jan Roskam wrote: > Hi > > (Sorry for topposting) > > numpy.ravel is faster than numpy.flatten (no copy) > numpy.empty is faster than numpy.zeros > numpy.fromiter might be useful to avoid the loop (just a hunch) > > Albert-Jan > Thanks, I'd forgotten the difference be

Re: counting unique numpy subarrays

2015-12-04 Thread Peter Otten
duncan smith wrote: > Hello, > I'm trying to find a computationally efficient way of identifying > unique subarrays, counting them and returning an array containing only > the unique subarrays and a corresponding 1D array of counts. The > following code works, but is a bit slow. > > ###

RE: counting unique numpy subarrays

2015-12-04 Thread Albert-Jan Roskam
Hi (Sorry for topposting) numpy.ravel is faster than numpy.flatten (no copy) numpy.empty is faster than numpy.zeros numpy.fromiter might be useful to avoid the loop (just a hunch) Albert-Jan > From: duncan@invalid.invalid > Subject: counting unique numpy subarrays > Date: Fri, 4 Dec 2015 19:43:

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
On Thursday, December 20, 2012 12:21:57 AM UTC+13, Thomas Bach wrote: > Hi, > > > > just as a side-note > > > > On Wed, Dec 19, 2012 at 02:45:13AM -0800, : > > > for word in list: > > > if word in dict: > > > count = dict[word] > > >

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
On Thursday, December 20, 2012 12:03:21 AM UTC+13, Steven D'Aprano wrote: > On Wed, 19 Dec 2012 02:45:13 -0800, dgcosgrave wrote: > > > > > Hi Iam just starting out with python...My code below changes the txt > > > file into a list and add them to an empty dictionary and print how often > > >

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread dgcosgrave
On Wednesday, December 19, 2012 11:55:28 PM UTC+13, Jussi Piitulainen wrote: > > > > > > Hi Iam just starting out with python...My code below changes the txt > > > file into a list and add them to an empty dictionary and print how > > > often the word occurs, but it only seems to recognise an

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread Thomas Bach
Hi, just as a side-note On Wed, Dec 19, 2012 at 02:45:13AM -0800, dgcosgr...@gmail.com wrote: > for word in list: > if word in dict: > count = dict[word] > count += 1 > dict[word] = count > else: > dict[wor

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread Steven D'Aprano
On Wed, 19 Dec 2012 02:45:13 -0800, dgcosgrave wrote: > Hi Iam just starting out with python...My code below changes the txt > file into a list and add them to an empty dictionary and print how often > the word occurs, but it only seems to recognise and print the last entry > of the txt file. Any

Re: counting how often the same word appears in a txt file...But my code only prints the last line entry in the txt file

2012-12-19 Thread Jussi Piitulainen
dgcosgr...@gmail.com writes: > Hi Iam just starting out with python...My code below changes the txt > file into a list and add them to an empty dictionary and print how > often the word occurs, but it only seems to recognise and print the > last entry of the txt file. Any help would be great. > >

Re: Counting the number of call of a function

2011-09-30 Thread Laurent Claessens
The keys of globals() are the _names_. You're giving it the function itself. Ow, ok. I didn't caught it. I understand now. > A decorator would be better. Yes. I keep the solution with foo=Wraper(foo) Thanks a lot all ! Laurent -- http://mail.python.org/mailman/listinfo/python-list

Re: Counting the number of call of a function

2011-09-29 Thread Chris Rebert
On Thu, Sep 29, 2011 at 10:08 AM, Laurent Claessens wrote: >   Hello > > >   Is it possible to count the number of time a function is called ? > Of course, if I've access to the source code, it's easy. > > I tried the following : > > def foo(): >    print "foo !" > > > class wraper(object): >    d

Re: Counting the number of call of a function

2011-09-29 Thread MRAB
On 29/09/2011 18:08, Laurent Claessens wrote: Hello Is it possible to count the number of time a function is called ? Of course, if I've access to the source code, it's easy. I tried the following : def foo(): print "foo !" class wraper(object): def __init__(self,fun): globals()[fun]=self.r

Re: Counting the number of call of a function

2011-09-29 Thread Chris Angelico
On Fri, Sep 30, 2011 at 3:08 AM, Laurent Claessens wrote: > class wraper(object): >    def __init__(self,fun): >        globals()[fun]=self.replacement >    def replacement(*args): >        print "I'm replaced" > > foo() > X=wraper(foo) > foo() > > I was hoping that globals()[foo] would be replace

Re: Counting the number of call of a function

2011-09-29 Thread Chris Angelico
On Fri, Sep 30, 2011 at 3:08 AM, Laurent Claessens wrote: > def foo(): >    print "foo !" > > > class wraper(object): >    def __init__(self,fun): >        globals()[fun]=self.replacement >    def replacement(*args): >        print "I'm replaced" > > foo() > X=wraper(foo) > foo() Are you able to

Re: Counting bits in large string / bit vector

2011-09-26 Thread Ian Kelly
On Sep 26, 2011 1:49 AM, wrote: > Is there an equivalent command in python that would immediately provide the number of set bits in a large bit vector/string Besides what others have said, if you expect the number of bits set to be small, you might just use a set. bits = set() # set bit 1000 bit

Re: Counting bits in large string / bit vector

2011-09-26 Thread casevh
On Sep 26, 12:56 am, Nizamov Shawkat wrote: > > Is there an equivalent command in python that would immediately provide the > > number of set bits in a large bit vector/string > > You might be able to achieve this using numpy boolean array and, e.g, > the arithmetic sum function or something simil

Re: Counting bits in large string / bit vector

2011-09-26 Thread Arnaud Delobelle
b = numpy.zeros(10**7, dtype=bool) for x in 3, 4, 6: b[10**x] = True > ... b.sum() > 3 Without numpy: >>> counts = [bin(i).count('1') for i in range(256)] >>> bytes = b"hello python"*10 >>> len(bytes)*8 960 >>> sum(map(counts.__getitem__, bytes)) 480 Pretty fast as wel

Re: Counting bits in large string / bit vector

2011-09-26 Thread Peter Otten
bmacin...@comcast.net wrote: > In Perl I can create a large bit vector as follows: > vec($bitmap,1000,1) = 0;# this will create a bit string of all > zeros > To set bits I may using commands like: > vec($bitmap,1000, 1) = 1 # turn on bit 1000 > vec($bitmap,1, 1) =

Re: Counting bits in large string / bit vector

2011-09-26 Thread Nizamov Shawkat
> Is there an equivalent command in python that would immediately provide the > number of set bits in a large bit vector/string > You might be able to achieve this using numpy boolean array and, e.g, the arithmetic sum function or something similar. There is also another library http://pypi.pytho

Re: counting lines of code

2010-01-23 Thread Michele Simionato
On Jan 22, 10:30 pm, Steve Holden wrote: > >> Oh, sorry, did I have the wrong opinion? > > > You had a condescending attitude. > > Towards someone who is fairly obviously not a Python neophyte. > > Please don't think we are telling you you can't have any opinion you > like. Just don't expect to ge

Re: counting lines of code

2010-01-23 Thread Michele Simionato
On Jan 22, 7:51 pm, Phlip wrote: > On Jan 21, 9:00 pm, Michele Simionato > wrote: > > > Just for fun I have run cloc on our trunk: > > > SUM:                8743    272238    215871   1470139 x   1.84 = > > 2708354.95 > > Nice! > > My favorite version of a cloc system can distinguish test from >

Re: counting lines of code

2010-01-22 Thread Wilbert Berendsen
Op donderdag 21 januari 2010 schreef Michele: > I need a small utility to count the lines of Python code in a > directory, traversing subdirectories and ignoring comments and > docstrings. sloccount can do this. http://www.dwheeler.com/sloccount/ Met vriendelijke groet, Wilbert Berendsen -- h

Re: counting lines of code

2010-01-22 Thread Steve Holden
Robert Kern wrote: > On 2010-01-21 15:31 , Phlip wrote: >> Aahz wrote: >>> In article >>> <7e09df6a-cda1-480e-a971-8f8a70ac4...@b9g2000yqd.googlegroups.com>, >>> Phlip wrote: On Jan 20, 11:20=A0pm, Michele Simionato wrote: > pylint does too many things, I want something fast that ju

Re: counting lines of code

2010-01-22 Thread Phlip
On Jan 21, 9:00 pm, Michele Simionato wrote: > Just for fun I have run cloc on our trunk: > > SUM:                8743    272238    215871   1470139 x   1.84 = > 2708354.95 Nice! My favorite version of a cloc system can distinguish test from production code. That's why I always use executable c

Re: counting lines of code

2010-01-21 Thread Michele Simionato
On Jan 21, 9:24 pm, Phlip wrote: > On Jan 20, 11:20 pm, Michele Simionato > wrote: > > > pylint does too many things, I want something fast that just counts > > the lines and can be run on thousands of files at once. > > cloc seems fine, I have just tried on 2,000 files and it gives me a > > repo

Re: counting lines of code

2010-01-21 Thread Robert Kern
On 2010-01-21 15:31 , Phlip wrote: Aahz wrote: In article <7e09df6a-cda1-480e-a971-8f8a70ac4...@b9g2000yqd.googlegroups.com>, Phlip wrote: On Jan 20, 11:20=A0pm, Michele Simionato wrote: pylint does too many things, I want something fast that just counts the lines and can be run on thousands

Re: counting lines of code

2010-01-21 Thread Phlip
Aahz wrote: In article <7e09df6a-cda1-480e-a971-8f8a70ac4...@b9g2000yqd.googlegroups.com>, Phlip wrote: On Jan 20, 11:20=A0pm, Michele Simionato wrote: pylint does too many things, I want something fast that just counts the lines and can be run on thousands of files at once. cloc seems fine,

Re: counting lines of code

2010-01-21 Thread Aahz
In article <7e09df6a-cda1-480e-a971-8f8a70ac4...@b9g2000yqd.googlegroups.com>, Phlip wrote: >On Jan 20, 11:20=A0pm, Michele Simionato >wrote: >> >> pylint does too many things, I want something fast that just counts >> the lines and can be run on thousands of files at once. >> cloc seems fine, I

Re: counting lines of code

2010-01-21 Thread Phlip
On Jan 20, 11:20 pm, Michele Simionato wrote: > pylint does too many things, I want something fast that just counts > the lines and can be run on thousands of files at once. > cloc seems fine, I have just tried on 2,000 files and it gives me a > report in just a few seconds. In my experience wit

Re: counting lines of code

2010-01-20 Thread Michele Simionato
On Jan 21, 8:12 am, Ben Finney wrote: > Michele Simionato writes: > > I need a small utility to count the lines of Python code in a > > directory, traversing subdirectories and ignoring comments and > > docstrings. I am sure there is already something doing that, what do > > you suggest? > > Any

Re: counting lines of code

2010-01-20 Thread Michele Simionato
I did not known about cloc, it does more that I need, but it looks cool (it is perl and not Python, by who cares? ;) Thanks, Michele -- http://mail.python.org/mailman/listinfo/python-list

Re: counting lines of code

2010-01-20 Thread Ben Finney
Michele Simionato writes: > I need a small utility to count the lines of Python code in a > directory, traversing subdirectories and ignoring comments and > docstrings. I am sure there is already something doing that, what do > you suggest? Any of the static code checkers (‘pylint’, ‘pyflakes’,

Re: counting lines of code

2010-01-20 Thread Mark Hammond
On 21/01/2010 5:51 PM, Michele Simionato wrote: I need a small utility to count the lines of Python code in a directory, traversing subdirectories and ignoring comments and docstrings. I am sure there is already something doing that, what do you suggest? I suggest typing your subject line into

Re: Counting number of objects

2009-01-27 Thread Scott David Daniels
Kottiyath wrote: So, in a higher level class, have a weakref list which contains a reference to each person. Total count will be len(list) at any time. Now, I couldnt find a weakref list - so I am using WeakKeyDictionary with the value as None - since len(dict) also should give me the data I ty

Re: Counting number of objects

2009-01-27 Thread Kottiyath
Thank you everyone for your very helpful comments and suggestions. I have interacted in other newsgroups, but this is the most helpful of them all. As per the comments, I have now decided to go with the weakref mechanism - as per Andreas suggestion, functionally it looks correct that the person sh

Re: Counting number of objects

2009-01-26 Thread Steve Holden
Mark Wooding wrote: > Andreas Waldenburger writes: > >> On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath >> wrote: >> >>> class a(object): >>> counter = 0 >>> def __new__(cls, *args, **kwargs): >>> a.counter += 1 >>> return object.__new__(cls, *args, **kwargs) > > Hmm.

Re: Counting number of objects

2009-01-26 Thread Andreas Waldenburger
On Mon, 26 Jan 2009 02:37:37 + Mark Wooding wrote: > > This looks OK, although I'd suggest using "cls.counter += 1" instead > > of "a.counter += 1" in the __new__() method. Just seems clearer to > > me, esp. when you think about subclassing. > > I'm not sure about clarity, but that would be

Re: Counting number of objects

2009-01-25 Thread Mark Wooding
Andreas Waldenburger writes: > On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath > wrote: > >> class a(object): >> counter = 0 >> def __new__(cls, *args, **kwargs): >> a.counter += 1 >> return object.__new__(cls, *args, **kwargs) Hmm. Exceptions raised during object cr

Re: Counting number of objects

2009-01-25 Thread Gabriel Genellina
En Sun, 25 Jan 2009 16:06:47 -0200, Andreas Waldenburger escribió: On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath wrote: I am creating a class called people - subclasses men, women, children etc. I want to count the number of people at any time. So, I created code like the following:

Re: Counting number of objects

2009-01-25 Thread Gabriel Genellina
En Sun, 25 Jan 2009 16:06:47 -0200, Andreas Waldenburger escribió: On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath wrote: I am creating a class called people - subclasses men, women, children etc. I want to count the number of people at any time. So, I created code like the following:

Re: Counting number of objects

2009-01-25 Thread Andreas Waldenburger
On Sun, 25 Jan 2009 09:23:35 -0800 (PST) Kottiyath wrote: > Hi, > I am creating a class called people - subclasses men, women, children > etc. > I want to count the number of people at any time. > So, I created code like the following: > > class a(object): > counter = 0 > def __new__(cls

Re: Counting number of objects

2009-01-25 Thread Steve Holden
Kottiyath wrote: > Hi, > I am creating a class called people - subclasses men, women, children > etc. > I want to count the number of people at any time. > So, I created code like the following: > > class a(object): > counter = 0 > def __new__(cls, *args, **kwargs): > a.counter +=

Re: Counting Elements in an xml file

2008-08-31 Thread Gerard flanagan
Ouray Viney wrote: Hi All: I am looking at writing a python script that will let me parse a TestSuite xml file that contains n number of TestCases. My goal is to be able to count the elements base on a key value pair in the xml node. Example I would like to be able to count the number of T

Re: Counting Elements in an xml file

2008-08-30 Thread Ouray Viney
On Aug 30, 2:17 pm, Paul Boddie <[EMAIL PROTECTED]> wrote: > On 30 Aug, 19:37, Ouray Viney <[EMAIL PROTECTED]> wrote: > > > > > > > > I would like to be able to count the number of TestCases that contain > > the "execute=true" but not the ones that contain "execute=false". > > With XPath-capable l

Re: Counting Elements in an xml file

2008-08-30 Thread Paul Boddie
On 30 Aug, 19:37, Ouray Viney <[EMAIL PROTECTED]> wrote: > > > > I would like to be able to count the number of TestCases that contain > the "execute=true" but not the ones that contain "execute=false". With XPath-capable libraries, it should be enough to execute an XPath query on the document. F

Re: Counting Elements in an xml file

2008-08-30 Thread Fredrik Lundh
Ouray Viney wrote: I am looking at writing a python script that will let me parse a TestSuite xml file that contains n number of TestCases. My goal is to be able to count the elements base on a key value pair in the xml node. Example I would like to be able to count the number of TestCases

Re: Counting Elements in an xml file

2008-08-30 Thread Marco Bizzarri
On Sat, Aug 30, 2008 at 7:37 PM, Ouray Viney <[EMAIL PROTECTED]> wrote: > Hi All: > > I am looking at writing a python script that will let me parse a > TestSuite xml file that contains n number of TestCases. > > My goal is to be able to count the elements base on a key > value pair in the xml nod

Re: Counting things fast - was Re: Summing a 2D list

2008-06-12 Thread Paddy
On Jun 12, 4:14 pm, Gerhard Häring <[EMAIL PROTECTED]> wrote: > Aidan wrote: > > does this work for you? > > > users = [1,1,1,2,2,3,4,4,4] > > score = [0,1,5,3,1,2,3,3,2] > > > d = dict() > > > for u,s in zip(users,score): > > if d.has_key(u): > > d[u] += s > > else: > > d[u] = s > > >

Re: counting using variable length string as base

2008-04-01 Thread rootkill
On Mar 27, 8:15 am, Grimsqueaker <[EMAIL PROTECTED]> wrote: > Hi, I'm fairly new to Python and to this list. I have a problem that > is driving me insane, sorry if it seems simple to everyone, I've been > fighting with it for a while. :)) > > I want to take a variable length string and use it as a

Re: counting using variable length string as base

2008-04-01 Thread Paul Rubin
Grimsqueaker <[EMAIL PROTECTED]> writes: > Basically I want to find every possible order of every combination. > Its easy if you know how many characters there will be in your string > (use nested for loops), but I am stuck with the variable length > string. I think I have to use a generator but I'

Re: counting using variable length string as base

2008-04-01 Thread David Fraser
On Mar 31, 8:18 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 31 Mar 2008 09:30:00 -0300, Graeme Glass <[EMAIL PROTECTED]> > escribió: > > > On Mar 27, 11:01 am, Peter Otten <[EMAIL PROTECTED]> wrote: > >> a b c aa ab ac ba bb bc ca cb cc aaa aab aac aba abb abc aca acb acc > >> baa

Re: counting using variable length string as base

2008-03-31 Thread Gabriel Genellina
En Mon, 31 Mar 2008 09:30:00 -0300, Graeme Glass <[EMAIL PROTECTED]> escribió: > On Mar 27, 11:01 am, Peter Otten <[EMAIL PROTECTED]> wrote: >> a b c aa ab ac ba bb bc ca cb cc aaa aab aac aba abb abc aca acb acc >> baa bab >> bac bba bbb bbc bca bcb bcc > > Here is a cool solution we came up

Re: counting using variable length string as base

2008-03-31 Thread Graeme Glass
On Mar 27, 11:01 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Grimsqueaker wrote: > > That seems to give me the items in the list back in an iterator. Am I > > using it incorrectly? > > With Dan's functions in cartesian.py you can do the following: > > >>> from cartesian import * > >>> def count(di

Re: counting using variable length string as base

2008-03-27 Thread castironpi
On Mar 27, 4:01 am, Peter Otten <[EMAIL PROTECTED]> wrote: > Grimsqueaker wrote: > > That seems to give me the items in the list back in an iterator. Am I > > using it incorrectly? > > With Dan's functions in cartesian.py you can do the following: > > >>> from cartesian import * > >>> def count(dig

Re: counting using variable length string as base

2008-03-27 Thread Peter Otten
Grimsqueaker wrote: > That seems to give me the items in the list back in an iterator. Am I > using it incorrectly? With Dan's functions in cartesian.py you can do the following: >>> from cartesian import * >>> def count(digits): ... args = [] ... while 1: ... args.append(di

Re: counting using variable length string as base

2008-03-27 Thread Grimsqueaker
OK, got that. If I use: for x in string_cartesian_product('abc'): print x I get: a b c What am I not understanding? Thank you -- http://mail.python.org/mailman/listinfo/python-list

Re: counting using variable length string as base

2008-03-27 Thread Steven D'Aprano
On Thu, 27 Mar 2008 00:33:21 -0700, Grimsqueaker wrote: > That seems to give me the items in the list back in an iterator. Am I > using it incorrectly? Given an iterator, you use it like this: for item in iterator: print item # or do something else If you're sure that the iterator is relat

Re: counting using variable length string as base

2008-03-27 Thread Diez B. Roggisch
Grimsqueaker schrieb: > That seems to give me the items in the list back in an iterator. Am I > using it incorrectly? No. Just put a list() around it. Diez -- http://mail.python.org/mailman/listinfo/python-list

Re: counting using variable length string as base

2008-03-27 Thread castironpi
On Mar 27, 2:33 am, Grimsqueaker <[EMAIL PROTECTED]> wrote: > That seems to give me the items in the list back in an iterator. Am I > using it incorrectly? Use list( it ). -- http://mail.python.org/mailman/listinfo/python-list

Re: counting using variable length string as base

2008-03-27 Thread Grimsqueaker
That seems to give me the items in the list back in an iterator. Am I using it incorrectly? -- http://mail.python.org/mailman/listinfo/python-list

Re: counting using variable length string as base

2008-03-26 Thread Dan Bishop
On Mar 27, 1:15 am, Grimsqueaker <[EMAIL PROTECTED]> wrote: > Hi, I'm fairly new to Python and to this list. I have a problem that > is driving me insane, sorry if it seems simple to everyone, I've been > fighting with it for a while. :)) > > I want to take a variable length string and use it as a

Re: counting lines using fileinput module

2008-02-13 Thread Robert
On Feb 13, 8:31 pm, 7stud <[EMAIL PROTECTED]> wrote: > On Feb 13, 6:47 pm, Robert <[EMAIL PROTECTED]> wrote: > > > > > I would like to count lines in a file using the fileinput module and I > > am getting an unusual output. > > ---

Re: counting lines using fileinput module

2008-02-13 Thread 7stud
On Feb 13, 6:47 pm, Robert <[EMAIL PROTECTED]> wrote: > I would like to count lines in a file using the fileinput module and I > am getting an unusual output. > --- > --- > #!/usr/bin/python > import fileinput > > # cycle thro

Re: counting lines using fileinput module

2008-02-13 Thread Gabriel Genellina
En Wed, 13 Feb 2008 23:47:11 -0200, Robert <[EMAIL PROTECTED]> escribió: > I would like to count lines in a file using the fileinput module and I > am getting an unusual output. > -- > #!/usr/bin/python > import fileinpu

Re: Counting method calls

2007-09-21 Thread chris . monsanto
On Sep 21, 7:15 pm, Ricardo Aráoz <[EMAIL PROTECTED]> wrote: > Hi, I know I'm being dumb but, why does it not work? > > >>> class MyList(list): > > ... def __init__(self): > ... self.calls = 0 > ... def __getattr__(self, name): > ... self.calls += 1 > ... return list

Re: Counting

2007-05-06 Thread Andy
.o0 -- http://mail.python.org/mailman/listinfo/python-list

Re: Counting

2007-05-04 Thread Steve Holden
James Stroud wrote: > James Stroud wrote: >> James Stroud wrote: [finally ...] > > I should really wait until I've had some coffee. Not continue, but break! > > > for i,line in enumerate(linelist): >line = line.split() >for k in line: > if keyword.iskeyword(k): >total += lin

Re: Counting

2007-04-29 Thread John Machin
On 30/04/2007 7:17 AM, James Stroud wrote: > [EMAIL PROTECTED] wrote: >> That's a short, abridged version of my code :) But, what I want is to >> count total# of keywords per line and print 'em. Rather than >> printing : >> >> The word 'and' belongs in line num: 1 >> The word 'del' belongs in line

Re: Counting

2007-04-29 Thread Andy
James - I pretty doubt about this - "c = line.count(k)" You might wanna recheck on that. I think it would be obvious how to write this: for i,line in enumerate(linelist): line = line.split() for k in line: if keyword.iskeyword(k):

Re: Counting

2007-04-29 Thread Andy
I pretty doubt about this - "c = line.count(k)" I might wanna recheck on that. - I think it would be obvious how to write this: for i,line in enumerate(linelist): line = line.split() for k in line: if keyword.iskeyword(k): c = line.count(k)

Re: Counting

2007-04-29 Thread James Stroud
[EMAIL PROTECTED] wrote: > That's a short, abridged version of my code :) But, what I want is to > count total# of keywords per line and print 'em. Rather than > printing : > > The word 'and' belongs in line num: 1 > The word 'del' belongs in line num: 1 > The word 'from' belongs in line num: 1 >

Re: Counting

2007-04-29 Thread castironpi
On Apr 29, 2:11 pm, Andy <[EMAIL PROTECTED]> wrote: > Hi, the file below will print all the keywords in a file and also the > line # of the keyword. What I couldn't figure out is to count those > keywords per line. For example - "Line #1 has 3 keywords" > > Can I do like - > > total[j] = total[j] +

Re: Counting

2007-04-29 Thread rockmode
That's a short, abridged version of my code :) But, what I want is to count total# of keywords per line and print 'em. Rather than printing : The word 'and' belongs in line num: 1 The word 'del' belongs in line num: 1 The word 'from' belongs in line num: 1 I want to print " Line #1 has 3 keywords

Re: Counting

2007-04-29 Thread James Stroud
James Stroud wrote: > James Stroud wrote: >> Andy wrote: >>> Hi, the file below will print all the keywords in a file and also the >>> line # of the keyword. What I couldn't figure out is to count those >>> keywords per line. For example - "Line #1 has 3 keywords" >>> >>> Can I do like - >>> >>> to

Re: Counting

2007-04-29 Thread James Stroud
James Stroud wrote: > Andy wrote: >> Hi, the file below will print all the keywords in a file and also the >> line # of the keyword. What I couldn't figure out is to count those >> keywords per line. For example - "Line #1 has 3 keywords" >> >> Can I do like - >> >> total[j] = total[j] + numwords(k

Re: Counting

2007-04-29 Thread James Stroud
Andy wrote: > Hi, the file below will print all the keywords in a file and also the > line # of the keyword. What I couldn't figure out is to count those > keywords per line. For example - "Line #1 has 3 keywords" > > Can I do like - > > total[j] = total[j] + numwords(k) > "Line number %d has %d

Re: Counting elements in a list wildcard

2006-04-26 Thread Edward Elliott
Iain King wrote: > steven = re.compile("Ste(v|ph|f|ff)(e|a)n") Also you can expand the RE a bit to improve readability: re.compile("Stev|Steph|Stef|Steff)(en|an)") -- http://mail.python.org/mailman/listinfo/python-list

Re: Counting elements in a list wildcard

2006-04-26 Thread Edward Elliott
Iain King wrote: > steven = re.compile("Ste(v|ph|f|ff)(e|a)n") > steven = ["Steven", "Stephen", "Stefen", "Steffen", "Stevan", > "Stephan", "Stefan", "Steffan"] > > I know which I'd rather type. 'Course, if you can use a ready-built > list of names... Oh I agree, I'd rather *type* the former, bu

Re: Counting elements in a list wildcard

2006-04-26 Thread Iain King
Edward Elliott wrote: > John Machin wrote: > > On 25/04/2006 6:26 PM, Iain King wrote: > >> iain = re.compile("(Ia(i)?n|Eoin)") > >> steven = re.compile("Ste(v|ph|f)(e|a)n") > > > > IMHO, the amount of hand-crafting that goes into a *general-purpose* > > phonetic matching algorithm is already bord

Re: Counting elements in a list wildcard

2006-04-25 Thread Edward Elliott
John Machin wrote: > On 25/04/2006 3:15 PM, Edward Elliott wrote: >> Phoneme matching seems overly complex and might >> grab things like Tsu-zi. > > It might *only* if somebody had a rush of blood to the head and devised > yet another phonetic key "algorithm". Tsuzi does *not* give the same > res

Re: Counting elements in a list wildcard

2006-04-25 Thread Edward Elliott
John Machin wrote: > On 25/04/2006 6:26 PM, Iain King wrote: >> iain = re.compile("(Ia(i)?n|Eoin)") >> steven = re.compile("Ste(v|ph|f)(e|a)n") > > IMHO, the amount of hand-crafting that goes into a *general-purpose* > phonetic matching algorithm is already bordering on overkill. Your > method usi

Re: Counting elements in a list wildcard

2006-04-25 Thread John Machin
On 25/04/2006 8:51 PM, Iain King wrote: > John Machin wrote: >> On 25/04/2006 6:26 PM, Iain King wrote: >>> hawkesed wrote: If I have a list, say of names. And I want to count all the people named, say, Susie, but I don't care exactly how they spell it (ie, Susy, Susi, Susie all work

Re: Counting elements in a list wildcard

2006-04-25 Thread Iain King
John Machin wrote: > On 25/04/2006 6:26 PM, Iain King wrote: > > hawkesed wrote: > >> If I have a list, say of names. And I want to count all the people > >> named, say, Susie, but I don't care exactly how they spell it (ie, > >> Susy, Susi, Susie all work.) how would I do this? Set up a regular >

Re: Counting elements in a list wildcard

2006-04-25 Thread John Machin
On 25/04/2006 6:26 PM, Iain King wrote: > hawkesed wrote: >> If I have a list, say of names. And I want to count all the people >> named, say, Susie, but I don't care exactly how they spell it (ie, >> Susy, Susi, Susie all work.) how would I do this? Set up a regular >> expression inside the count?

Re: Counting elements in a list wildcard

2006-04-25 Thread John Machin
On 25/04/2006 3:15 PM, Edward Elliott wrote: > Phoneme matching seems overly complex and might > grab things like Tsu-zi. It might *only* if somebody had a rush of blood to the head and devised yet another phonetic key "algorithm". Tsuzi does *not* give the same result as any of Suzi, Suzie, Su

Re: Counting elements in a list wildcard

2006-04-25 Thread Iain King
hawkesed wrote: > If I have a list, say of names. And I want to count all the people > named, say, Susie, but I don't care exactly how they spell it (ie, > Susy, Susi, Susie all work.) how would I do this? Set up a regular > expression inside the count? Is there a wildcard variable I can use? > He

Re: Counting elements in a list wildcard

2006-04-24 Thread Edward Elliott
Dave Hughes wrote: > Another algorithm that might interest isn't based on "sounds-like" but > instead computes the number of transforms necessary to get from one > word to another: the Levenshtein distance. A C based implementation > (with Python interface) is available: I don't know what algorith

  1   2   >