writing to lists within a dictionary

2007-09-20 Thread cokofreedom
I am trying to write a basic anagram system, that takes a text file line by line and by sorting the string into its alphabetical form compares it to keys within a dictionary. If it matches a key I want to add it (in its unordered form) to a list for that key. So far this is what I have import sy

Re: os.path.getmtime() and compare with a date type

2007-09-20 Thread cokofreedom
On Sep 20, 5:31 pm, [EMAIL PROTECTED] wrote: > Hi, > I am new to python and are tryint to write a simple program delete log > files that are older than 30 days. > > So I used os.path.getmtime(filepath) and compare it with a date but it > does not compile. > > threshold_time = datetime.date.today()

Re: Finding Peoples' Names in Files

2007-10-11 Thread cokofreedom
On Oct 11, 5:22 pm, brad <[EMAIL PROTECTED]> wrote: > Crazy question, but has anyone attempted this or seen Python code that > does? For example, if a text file contained 'Guido' and or 'Robert' and > or 'Susan', then we should return True, otherwise return False. Can't you just use the string fun

Re: Finding Peoples' Names in Files

2007-10-11 Thread cokofreedom
On Oct 11, 5:40 pm, brad <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > On Oct 11, 5:22 pm, brad <[EMAIL PROTECTED]> wrote: > >> Crazy question, but has anyone attempted this or seen Python code that > >> does? For example, if a text file contained 'Guido' and or 'Robert' and > >> or 'Su

Re: Order by value in dictionary

2007-10-17 Thread cokofreedom
On Oct 17, 3:39 pm, Abandoned <[EMAIL PROTECTED]> wrote: > Hi.. > I have a dictionary like these: > a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000 > element > I want to sort this by value and i want to first 100 element.. > Result must be: > [b, a, d, c .] ( first 100 elemen

Re: Order by value in dictionary

2007-10-17 Thread cokofreedom
On Oct 17, 4:06 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Diez B. Roggisch wrote: > > Abandoned wrote: > > >> Hi.. > >> I have a dictionary like these: > >> a={'a': '1000', 'b': '18000', 'c':'40', 'd': '600'} .. 100.000 > >> element > >> I want to sort this by value and i want to firs

Re: Best way to generate alternate toggling values in a loop?

2007-10-18 Thread cokofreedom
On Oct 18, 3:48 pm, Iain King <[EMAIL PROTECTED]> wrote: > On Oct 18, 2:29 am, Grant Edwards <[EMAIL PROTECTED]> wrote: > > > > > On 2007-10-17, Debajit Adhikary <[EMAIL PROTECTED]> wrote: > > > > # Start of Code > > > > def evenOdd(): > > > values = ["Even", "Odd"] > > > state = 0 > > >

Re: Noob questions about Python

2007-10-19 Thread cokofreedom
On Oct 19, 1:44 am, MRAB <[EMAIL PROTECTED]> wrote: > On Oct 18, 7:05 am, Michele Simionato <[EMAIL PROTECTED]> > wrote:> On Oct 17, 5:58 pm, Ixiaus <[EMAIL PROTECTED]> wrote: > > > > def bin2dec(val): > > > li = list(val) > > > li.reverse() > > > res = [int(li[x])*2**x for x in range(l

Re: Iteration for Factorials

2007-10-22 Thread cokofreedom
On Oct 22, 2:43 pm, Marco Mariani <[EMAIL PROTECTED]> wrote: > Py-Fun wrote: > > def itforfact(n): > > while n<100: > > print n > > n+1 > > n = input("Please enter a number below 100") > > You function should probably return something. After that, you can see > what happens with

Re: Iteration for Factorials

2007-10-23 Thread cokofreedom
On Oct 23, 8:53 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Marco Mariani" wrote: > > > I don't see how my answer is in any way worse than those based on > > lambda. Maybe I'm just envious because when I was his age I couldn't > > google for answers. He should at least be able to do th

Re: Python - why don't this script work?

2007-10-23 Thread cokofreedom
On Oct 23, 6:50 am, Ohmster <[EMAIL PROTECTED]> wrote: > Adam Atlas <[EMAIL PROTECTED]> wrote in news:1193108392.089611.91170 > @v29g2000prd.googlegroups.com: > > > I think you're executing it as a shell script. Run "python image- > > harvester.py", or add "#!/usr/bin/env python" to the top of the

Anagrams

2007-10-23 Thread cokofreedom
This was from a random website I found on practising good programming techniques and I thought I'd see what ways people could find to write out this example. Below are my two examples (which should work...). I am merely interested in other techniques people have (without resorting to overusage of

Re: Iteration for Factorials

2007-10-23 Thread cokofreedom
On Oct 23, 1:58 pm, [EMAIL PROTECTED] wrote: > On 22 oct, 23:39, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > Nope, still doesn't work: > > > def fact(x): > > return reduce(operator.mul,xrange(1,x+1),1) > > > fact() should raise an exception if x is negative. > > So, where is the pr

Re: Better writing in python

2007-10-24 Thread cokofreedom
On Oct 24, 4:15 pm, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Oct 24, 2:02 pm, [EMAIL PROTECTED] wrote: > > > > > On Oct 24, 7:09 am, Alexandre Badez <[EMAIL PROTECTED]> wrote: > > > > I'm just wondering, if I could write a in a "better" way this code > > > > lMandatory = [] > > > lOptional = []

Re: Anagrams

2007-10-24 Thread cokofreedom
On Oct 24, 2:28 am, Paul Hankin <[EMAIL PROTECTED]> wrote: > On Oct 23, 9:21 am, [EMAIL PROTECTED] wrote: > > > This one uses a dictionary to store prime values of each letter in the > > alphabet and for each line multiple the results of the characters > > (which is unique for each anagram) and add

Re: while within while

2007-10-29 Thread cokofreedom
On Oct 29, 4:28 pm, [EMAIL PROTECTED] wrote: > On Oct 29, 9:26 am, Steven D'Aprano <[EMAIL PROTECTED] > > > > cybersource.com.au> wrote: > > On Sun, 28 Oct 2007 21:02:02 -0400, Shawn Minisall wrote: > > > Thanks a lot for your suggestions. Unfortunately, a lot of the issues > > > brought up were s

Re: How to get a set of keys with largest values?

2007-11-12 Thread cokofreedom
On Nov 12, 10:07 am, Davy <[EMAIL PROTECTED]> wrote: > Hi all, > > I have a dictionary with n elements, and I want to get the m(m<=n) > keys with the largest values. > > For example, I have dic that includes n=4 elements, I want m=2 keys > have the largest values) > dic = {0:4,3:1,5:2,7:8} > So, th

Re: Looking for a good Python environment

2007-11-13 Thread cokofreedom
On Nov 13, 10:56 am, bramble <[EMAIL PROTECTED]> wrote: > On Nov 10, 4:48 am, Paul Rudin <[EMAIL PROTECTED]> wrote: > > > jwelby <[EMAIL PROTECTED]> writes: > > > > The main reason I have used Eclipse for larger, team based, projects > > > is for the source control plug-ins. Eclipse has plug-in sup

Re: Loop three lists at the same time?

2007-11-13 Thread cokofreedom
On Nov 13, 11:46 am, Davy <[EMAIL PROTECTED]> wrote: > Hi all, > > I have three lists with the same length. Is there any method to loop > the three lists without a loop counter? > > Best regards, > Davy What exactly do you mean? Are you trying to loop them together with the same ´count´. "for loo

Re: Arrays

2007-11-14 Thread cokofreedom
On Nov 14, 3:51 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Modules contain objects. When you want to import a specific set of > objects contained in a module into the local namespace, you use: > from import > For example: > from math import sqrt > from math import sin, cos > > If

Re: why it is invalid syntax?

2007-11-22 Thread cokofreedom
On Nov 22, 10:58 am, "Guilherme Polo" <[EMAIL PROTECTED]> wrote: > 2007/11/22, Stef Mientki <[EMAIL PROTECTED]>: > > > > > alf wrote: > > > Hi, > > > > I wonder why it is an invalid syntax: > > > > >>> if 1: if 1: if 1: print 1 > > > File "", line 1 > > > if 1: if 1: if 1: print 1 > > > > or

Re: Problems with if/elif statement syntax

2007-11-22 Thread cokofreedom
On Nov 22, 12:16 pm, oj <[EMAIL PROTECTED]> wrote: > On Nov 22, 11:09 am, Neil Webster <[EMAIL PROTECTED]> wrote: > > > > > Hi all, > > > I'm sure I'm doing something wrong but after lots of searching and > > reading I can't work it out and was wondering if anybody can help? > > > I've got the foll

Re: Problems with if/elif statement syntax

2007-11-22 Thread cokofreedom
On Nov 22, 12:33 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On 22 Nov, 12:09, Neil Webster <[EMAIL PROTECTED]> wrote: > > > > > Hi all, > > > I'm sure I'm doing something wrong but after lots of searching and > > reading I can't work it out and was wondering if anybody can help? > > > I'v

Re: why it is invalid syntax?

2007-11-22 Thread cokofreedom
On Nov 22, 5:46 pm, Stargaming <[EMAIL PROTECTED]> wrote: > On Thu, 22 Nov 2007 03:24:48 -0800, cokofreedom wrote: > > On Nov 22, 10:58 am, "Guilherme Polo" <[EMAIL PROTECTED]> wrote: > >> 2007/11/22, Stef Mientki <[EMAIL PROTECTED]>: > > >&g

Re: Very basic, sorting a list ???

2007-11-29 Thread cokofreedom
On Nov 29, 10:40 am, Stef Mientki <[EMAIL PROTECTED]> wrote: > Peter Decker wrote: > > On Nov 28, 2007 7:22 PM, stef mientki <[EMAIL PROTECTED]> wrote: > >> print 'xx3',ordered_list.sort() > > > The sort() method returns None. It sorts the list in place; it doesn't > > return a copy of the sort

Re: "Python" is not a good name, should rename to "Athon"

2007-12-03 Thread cokofreedom
The only reason to change the name would be because of some serious bad PR that came onto Python, thus causing its branding name to be catagorized as something bad. However this is not the case, presently, and the brand name is well established and accepted. There is no reason to change its name a

Re: "Python" is not a good name, should rename to "Athon"

2007-12-04 Thread cokofreedom
On Dec 4, 11:36 am, MarkE <[EMAIL PROTECTED]> wrote: > Ithon Pie - Fun -- http://mail.python.org/mailman/listinfo/python-list

"do" as a keyword

2007-12-11 Thread cokofreedom
First off let me state that I really enjoy using Python. I am a 3rd year student and have been using python for 3 months, (thanks to trac!). I do not consider myself an experienced or clever programmer, but I am able to get by. Something I love about Python is that almost everything you do can be

Re: Newbie NameError problem

2007-12-12 Thread cokofreedom
On Dec 12, 5:51 pm, Paul Rudin <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > I don't understand what I don't understand in the following: > > I haven't tried to understand what your code is doing - but the > NameError arises because you try to use Loc before its definition. Put > the d

Re: Newbie NameError problem

2007-12-13 Thread cokofreedom
On Dec 12, 7:03 pm, Paul Rudin <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > On Dec 12, 5:51 pm, Paul Rudin <[EMAIL PROTECTED]> wrote: > >> [EMAIL PROTECTED] writes: > >> > I don't understand what I don't understand in the following: > > >> I haven't tried to understand what your code

Re: alternating string replace

2008-01-09 Thread cokofreedom
On Jan 9, 11:34 am, cesco <[EMAIL PROTECTED]> wrote: > Hi, > > say I have a string like the following: > s1 = 'hi_cat_bye_dog' > and I want to replace the even '_' with ':' and the odd '_' with ',' > so that I get a new string like the following: > s2 = 'hi:cat,bye:dog' > Is there a common recipe t

Re: alternating string replace

2008-01-09 Thread cokofreedom
Designed a pretty basic way that is "acceptable" on small strings. evenOrOdd = True s1 = "hi_cat_bye_dog_foo_bar_red" s2 = "" for i in s1: if i == '_': if evenOrOdd: s2 += ':' evenOrOdd = not evenOrOdd else: s2 += ',' evenOrOdd

Re: alternating string replace

2008-01-10 Thread cokofreedom
On Jan 10, 3:46 am, [EMAIL PROTECTED] wrote: > Gordon C: > > > This is very cool stuff but I suspect that the code is unreadable > > to many readers, including me. Just for fun here is a complete program, > > written in Turbo Pascal, circa 1982, that does the job. Readable > > n'est pas? > > I thi

Re: python recursive function

2008-01-11 Thread cokofreedom
On Jan 11, 9:46 am, Gary Herron <[EMAIL PROTECTED]> wrote: > Tom_chicollegeboy wrote: > > here is what I have to do: > > > This question involves a game with teddy bears. The game starts when I > > give you some bears. You then start giving me back some bears, but you > > must follow these rules (w

Re: python recursive function

2008-01-11 Thread cokofreedom
> Stylistically I prefer 'if not n % 5', looks neater. > As for your assignment, the hardest task will be creating an effective > method of ensuring you recurse through all possibilities. I was chatting to a friend about the 'if not n % 5' and while I am happy to use it saying that when 5 % 5 is F

Re: alternating string replace

2008-01-11 Thread cokofreedom
evenOrOdd = True s1, s2 = "hi_cat_bye_dog_foo_bar_red", "" for i in s1: if i == '_': s2 += ':' if evenOrOdd else ',' evenOrOdd = not evenOrOdd else: s2 += i print s2 Presently I cannot work out how to use .join instead of += ... While I realise this is producing a new

Re: Python too slow?

2008-01-15 Thread cokofreedom
A lecturer gave me the perfect answer to the question of speed. "You have two choices when it comes to programming. Fast code, or fast coders." -- http://mail.python.org/mailman/listinfo/python-list

Re: common problem - elegant solution sought

2008-01-15 Thread cokofreedom
> I have a list of tuples (Unique_ID,Date) both of which are strings. > I want to delete the tuple (element) with a given Unique_ID, but > I don't known the corresponding Date. > > My straight forward solution is a bit lengthy, e.g. > > L=[("a","070501"),("b","080115"),("c","071231")] Do they hav

Re: Python too slow?

2008-01-15 Thread cokofreedom
On Jan 15, 1:28 pm, Paul Rudin <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > A lecturer gave me the perfect answer to the question of speed. > > > "You have two choices when it comes to programming. Fast code, or fast > > coders." > > Yes, although it's more a continuum than that sugge

Re: no pass-values calling?

2008-01-16 Thread cokofreedom
On Jan 16, 1:21 pm, "Neil Cerutti" <[EMAIL PROTECTED]> wrote: > On Jan 15, 2008 10:09 PM, J. Peng <[EMAIL PROTECTED]> wrote: > > > Hello, > > > I saw this statement in Core Python Programming book, > > > All arguments of function calls are made by reference, meaning that > > any changes to these pa

Re: no pass-values calling?

2008-01-16 Thread cokofreedom
> > No, my hypothesis is that Python's assignment statement semantics are > the tricky part--once you understand them, the utter simplicity of > Python's argument passing semantics will be evident. Indeed, I find the simple nature of it and the fact things tend not to change is extremely useful. I

Re: Python too slow?

2008-01-16 Thread cokofreedom
On Jan 16, 5:52 pm, Ed Jensen <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > A lecturer gave me the perfect answer to the question of speed. > > > "You have two choices when it comes to programming. Fast code, or fast > > coders." > > "You're either with us, or against us." > > Georg

Re: Loop in a loop?

2008-01-17 Thread cokofreedom
On Jan 17, 1:21 pm, Sacred Heart <[EMAIL PROTECTED]> wrote: > Hi, > I'm new to Python and have come across a problem I don't know how to > solve, enter com.lang.python :) > > I'm writing some small apps to learn the language, and I like it a lot > so far. > > My problem I've stumbled upon is that I

Re: Loop in a loop?

2008-01-17 Thread cokofreedom
On Jan 17, 2:52 pm, Chris <[EMAIL PROTECTED]> wrote: > On Jan 17, 2:35 pm, [EMAIL PROTECTED] wrote: > > > > > On Jan 17, 1:21 pm, Sacred Heart <[EMAIL PROTECTED]> wrote: > > > > Hi, > > > I'm new to Python and have come across a problem I don't know how to > > > solve, enter com.lang.python :) > >

Re: Is this a bug, or is it me?

2008-01-17 Thread cokofreedom
On Jan 17, 4:05 pm, [EMAIL PROTECTED] wrote: > Hello all, > For some reason, the following does not work : > > class C: > TYPES = [None] > DICT = {} > for Type in TYPES: > DICT.update((E,Type) for E in [1]) > > >>> NameError: global name 'Type' is not defined > > What do you thi

Re: Loop in a loop?

2008-01-17 Thread cokofreedom
> > > Yes, small typo there. > > > Okey, so if my array1 is has 4 elements, and array2 has 6, it won't > > loop trough the last 2 in array2? How do I make it do that? > > > Please gentlemen: Python has no builtin type named 'array', so >s/array/list/g > > > Just pad your shortest list. I agr

Re: Is this a bug, or is it me?

2008-01-17 Thread cokofreedom
On Jan 17, 4:59 pm, "Neil Cerutti" <[EMAIL PROTECTED]> wrote: > On Jan 17, 2008 10:44 AM, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > > > "Neil Cerutti" <[EMAIL PROTECTED]> writes: > > > > You cannot access a class's class variables in it's class-statement > > > scope, since the name of the type is

Re: Loop in a loop?

2008-01-18 Thread cokofreedom
> Hehe.. I remember seeing a similar one for Java and "Hello world" > using more and more elaborate abstractions and design patterns but I > can't find the link. > > George This is not linked to Java but deals with Hello World http://www.ariel.com.au/jokes/The_Evolution_of_a_Programmer.html -- h

Re: Bug in __init__?

2008-01-21 Thread cokofreedom
Is there no way of adding a possible warning message (that obviously could be turned off) to warn users of possible problems linked to using mutable types as parameters? Seems to me this could save users a few minutes/hours of headaches and headscratching. (The biggest issue affecting new programm

Re: Default attribute values pattern

2008-01-21 Thread cokofreedom
> Grab(argdict, key, default) is argdict.pop(key, default) "pop() raises a KeyError when no default value is given and the key is not found." > def grab(kw, key, default=None): >try: > return kw.pop(key) >except KeyError: > return default So Bruno's technique seems to me to be

Re: Just for fun: Countdown numbers game solver

2008-01-21 Thread cokofreedom
On Jan 21, 11:29 am, Terry Jones <[EMAIL PROTECTED]> wrote: > > "dg" == dg google groups <[EMAIL PROTECTED]> writes: > > dg> It's great how many different sorts of solutions (or almost solutions) > dg> this puzzle has generated. Speedwise, for reference my solution posted > dg> above takes abou

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread cokofreedom
On Jan 23, 9:45 am, Kristian Domke <[EMAIL PROTECTED]> wrote: > Hello to all > > I am trying to learn python at the moment studying an example program > (cftp.py from the twisted framework, if you want to know) > > There I found a line > > foo = (not f and 1) or 0 > > In this case f may be None or

Re: HTML parsing confusion

2008-01-23 Thread cokofreedom
> The pages I'm trying to write this code to run against aren't in the > wild, though. They are static html files on my company's lan, are very > consistent in format, and are (I believe) valid html. Obvious way to check this is to go to http://validator.w3.org/ and see what it tells you about you

Re: Why not 'foo = not f' instead of 'foo = (not f or 1) and 0'?

2008-01-23 Thread cokofreedom
Sorry, posted to quickly. Yes your logic is correct about the "logic" of the return, but theirs actually differs in what it returns, and I am guessing it is an important change. Where is this "foo" used? Perhaps its value is used in a way a boolean return couldn't be? Just a note, with these kind

Re: Stripping whitespace

2008-01-24 Thread cokofreedom
On Jan 24, 8:21 am, ryan k <[EMAIL PROTECTED]> wrote: > On Jan 23, 6:30 pm, John Machin <[EMAIL PROTECTED]> wrote: > > > On Jan 24, 9:50 am, ryan k <[EMAIL PROTECTED]> wrote: > > > > Steven D'Aprano, you are a prick. > > > And your reasons for coming to that stridently expressed conclusion > > afte

Re: optional static typing for Python

2008-01-28 Thread cokofreedom
On Jan 28, 11:42 am, "Russ P." <[EMAIL PROTECTED]> wrote: > On Jan 28, 1:51 am, Bruno Desthuilliers > > > [EMAIL PROTECTED]> wrote: > > Russ P. a écrit :> A while back I came across a tentative proposal from way > > back in 2000 > > > for optional static typing in Python: > > > (snip) > > > > In

Re: Removal of element from list while traversing causes the next element to be skipped

2008-01-30 Thread cokofreedom
On Jan 30, 9:50 am, Santiago Romero <[EMAIL PROTECTED]> wrote: > On 30 ene, 08:09, Paul Rubin wrote: > > > Santiago Romero <[EMAIL PROTECTED]> writes: > > > > > >>> li = [1,2,3,4,5] > > > > >>> filter(lambda x: x != 3, li) > > > > [1, 2, 4, 5] > > > > I haven't measure

Re: Removal of element from list while traversing causes the next element to be skipped

2008-01-30 Thread cokofreedom
Anyone else noticed that the OP has not actually replied to any of the suggestions... -- http://mail.python.org/mailman/listinfo/python-list

Re: Why not a Python compiler?

2008-02-05 Thread cokofreedom
On Feb 5, 9:19 am, Santiago Romero <[EMAIL PROTECTED]> wrote: > ( Surely if this question has been asked for a zillion of times... ) > ( and sorry for my english! ) > > I'm impressed with python. I'm very happy with the language and I > find Python+Pygame a very powerful and productive way of w

Re: Why does list have no 'get' method?

2008-02-08 Thread cokofreedom
On Feb 8, 8:23 am, Carl Banks <[EMAIL PROTECTED]> wrote: > On Feb 7, 8:44 am, Steve Holden <[EMAIL PROTECTED]> wrote: > > > [EMAIL PROTECTED] wrote: > > > I'd like to know what others think about it, about this anti-feature. > > > What I can say is that other computer languages too think that boole

Re: How to autorun a python script when a specific user logs on?

2008-02-08 Thread cokofreedom
On Feb 8, 1:30 am, "jack trades" <[EMAIL PROTECTED]> wrote: > "Mike Hjorleifsson" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > on windows you can put this in HKEY_Local_Machine\Software\Microsoft > > \Windows\Current Version\Run and it will run at logon (or fast user > > sw

Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-11 Thread cokofreedom
On Feb 12, 7:16 am, Jeff Schwab <[EMAIL PROTECTED]> wrote: > Erik Max Francis wrote: > > Jeff Schwab wrote: > > >> Erik Max Francis wrote: > >>> Grant Edwards wrote: > > On 2008-02-12, Jeff Schwab <[EMAIL PROTECTED]> wrote: > > Fair enough! > > Dear me, what's Usenet coming to these d

Re: OT: Speed of light [was Re: Why not a Python compiler?]

2008-02-13 Thread cokofreedom
> And the rest of us just use SI. (And if you bring up the > _kilogram-force_, I'll just cry.) SI = Super Incredible? Awesome name for Force/Mass / NewItemOfClothing2050! -- http://mail.python.org/mailman/listinfo/python-list

Re: ways to declare empty set variable

2008-02-13 Thread cokofreedom
The irony that, x = (,) produces an error. Personally I would of thought it would be a better example of an empty tuple than anything else, but it still isn't that readable. The use of dict/list/tuple/set seems to stand out a lot better, makes it readable! Else in a few years you'll have §x§ = !^

Regular Expression for Prime Numbers (or How I came to fail at them, and love the bomb)

2008-02-13 Thread cokofreedom
I was reading up on this site [http://www.noulakaz.net/weblog/ 2007/03/18/a-regular-expression-to-check-for-prime-numbers/] of an interesting way to work out prime numbers using Regular Expression. However my attempts to use this in Python keep returning none (obviously no match), however I don't

Re: Regular Expression for Prime Numbers (or How I came to fail at them, and love the bomb)

2008-02-14 Thread cokofreedom
> hmm... interesting > > here is another way you can find prime > numbershttp://love-python.blogspot.com/2008/02/find-prime-number-upto-100-nu... > Sadly that is pretty slow though... If you don't mind readability you can make the example I gave into five lines. def p(_): if _<3:return[2]if _=

Re: Assignment saves time?

2008-02-15 Thread cokofreedom
> $ python -m timeit -s 'l=[]' 'len(l)==1000' > 100 loops, best of 3: 0.256 usec per loop > $ python -m timeit -s 'l=[]' 'len(l)==1000' > 100 loops, best of 3: 0.27 usec per loop > > $ python -m timeit -s 'l=[]' 's=len(l); s==1000' > 100 loops, best of 3: 0.287 usec per loop > $ python

Re: Current Fastest Python Implementation?

2008-02-18 Thread cokofreedom
On Feb 18, 9:37 am, Stefan Behnel <[EMAIL PROTECTED]> wrote: > samuraisam wrote: > > Has anyone done any recent testing as to which current python > > implementation is the quickest? > > Search for a recent thread on CPython and IronPython. > > > Perhaps for Django development - > > though the curr

Re: TRAC - Trac, Project Leads, Python, and Mr. Noah Kantrowitz (sanitizer)

2008-02-18 Thread cokofreedom
Dear Ilias, Post in a single reply. Coko -- http://mail.python.org/mailman/listinfo/python-list

Re: What's "the standard" for code docs?

2008-02-20 Thread cokofreedom
On Feb 20, 9:12 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > Are people really writing pure HTML snippets in docstrings to document > > each module/class/method? For anything other than a toy project? > > > One of the main reasons I'm considering moving to epydoc + reST is > > precisely b

Re: Double underscores -- ugly?

2008-02-20 Thread cokofreedom
So people's problem with __word__ is that it is not very readable? How so, it stands out on page, it clearly is different from other objects and doesn't abuse other symbols that generally have a meaning based on their use. I haven't seen a single alternative that really stands out as much as __wo

Re: Double underscores -- ugly?

2008-02-21 Thread cokofreedom
On Feb 21, 3:31 am, [EMAIL PROTECTED] wrote: > On Feb 19, 8:20 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > > > > > [EMAIL PROTECTED] wrote: > > > On Feb 19, 10:26 am, Wildemar Wildenburger > > > <[EMAIL PROTECTED]> wrote: > > >> Jason wrote: > > >>> Hmm. I must be the only person who doesn't thi

Re: newbie in python

2008-02-21 Thread cokofreedom
> >Can someone help me to get in the right track, and get a good move? > > http://wiki.python.org/moin/BeginnersGuide http://www.diveintopython.org/ -- http://mail.python.org/mailman/listinfo/python-list

Re: How about adding rational fraction to Python?

2008-02-26 Thread cokofreedom
What is it with people and double++ posting... If you have a lot to say, say it together and take the time to slow down, re-read it and not just fly it out, line by line, by line, by line... To answer only the following: > That's creepy for people that are new to programming and doesn't know > h

Re: Converting a string to the most probable type

2008-03-10 Thread cokofreedom
The trick in the case of when you do not want to guess, or the choices grow too much, is to ask the user to tell you in what format they want it and format according to their wishes. Neatly avoids too much guessing and isn't much extra to add. -- http://mail.python.org/mailman/listinfo/python-lis

Re: Creating a file with $SIZE

2008-03-12 Thread cokofreedom
On Mar 12, 2:44 pm, Robert Bossy <[EMAIL PROTECTED]> wrote: > Matt Nordhoff wrote: > > Robert Bossy wrote: > > >> k.i.n.g. wrote: > > >>> I think I am not clear with my question, I am sorry. Here goes the > >>> exact requirement. > > >>> We use dd command in Linux to create a file with of required

Re: List mutation method gotcha - How well known?

2008-03-13 Thread cokofreedom
On Mar 13, 8:36 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > Hi, > > I am surprised that it took me so long to bloody my nose on this one. > > It must be well known - and I would like to find out how well known. > > So here is a CLOSED BOOK multiple choice question - no RTFM, > no playing

Re: List mutation method gotcha - How well known?

2008-03-13 Thread cokofreedom
Still, I suppose this is a gotcha for a lot of people, just follow the good advice Paul said; "By Python convention, methods that mutate the object return None, and also stuff that returns None doesn't generate output at the interactive prompt." And you should survive most. -- http://mail.python.

Re: Immutable and Mutable Types

2008-03-17 Thread cokofreedom
> >>> a = 1 > >>> b = 1 > >>> a is b > True > >>> id(a) > 10901000 > >>> id(b) > 10901000 Isn't this because integers up to a certain range are held in a single memory location, thus why they are the same? -- http://mail.python.org/mailman/listinfo/python-list

globals() using For Loop against Generator

2008-03-18 Thread cokofreedom
if __name__ == '__main__': print "Globals (For Loop):" try: for i in globals(): print "\t%s" % i except RuntimeError: print "Only some globals() printed\n" else: print "All globals() printed\n" print "Globals (Generator):" try: p

Timeit

2009-02-18 Thread cokofreedom
I've having an annoying problem at the moment. I'm writing code for the travelling salesmen problem and comparing different techniques. But I've having a problem using timeit. I have a file called "testplatform.py" that contains 4 class: Test() - which is called first to create the cities/routes t

Re: Is using range() in for loops really Pythonic?

2008-05-14 Thread cokofreedom
On May 14, 8:37 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Tue, 13 May 2008 10:20:41 -0700, John Nagle wrote: > > Matt Nordhoff wrote: > > >> Well, you should use "xrange(10)" instead of "range(10)". > > >CPython really is naive. That sort of thing should be a > > compile-tim

Re: Misuse of list comprehensions?

2008-05-21 Thread cokofreedom
''.join(seen.add(c) or c for c in s if c not in seen) >From what I can understand... .join will be a String of unique 'c' values. 'seen.add(c) or c' will always point to the second statement 'c' because seen.add(c) returns None. 'if c not in seen' will ensure 'c' being added to both the .join a

Re: C-like assignment expression?

2008-05-21 Thread cokofreedom
On May 21, 3:12 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On May 21, 1:47 pm, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > > > Although that solution is pretty, it is not the canonical solution > > because it doesn't cover the important case of "if" bodies needing to > > access common vari

Re: C-like assignment expression?

2008-05-21 Thread cokofreedom
> > And wastes time. regular expressions can become expensive to match - doing > it twice might be hurtful. > > Diez match = (my_re1.match(line) or my_re2.match(line)) or my_re3.match(line) ? -- http://mail.python.org/mailman/listinfo/python-list

Re: C-like assignment expression?

2008-05-21 Thread cokofreedom
On May 21, 4:09 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > >> And wastes time. regular expressions can become expensive to match - > >> doing it twice might be hurtful. > > >> Diez > > > match = (my_re1.match(line) or my_re2.match(line)) or > > my_re3.match(lin

Re: C-like assignment expression?

2008-05-21 Thread cokofreedom
On May 21, 4:57 pm, "inhahe" <[EMAIL PROTECTED]> wrote: > one of the few things i miss from C is being able to use assignment in > expressions. that's the only thing, really. > also there's no switch/case, you have to use a dictionary of functions > instead, although i rarely need that, usually i

Re: php vs python

2008-05-28 Thread cokofreedom
On May 28, 1:42 pm, Michael Fesser <[EMAIL PROTECTED]> wrote: > .oO(Ivan Illarionov) > > >No. Language does matter. > > And the weather. > > If you know how to program, you can write good code in any language if > you're familiar enough with it. Many people write good code in PHP, and > many write

Re: Tuple of coordinates

2008-05-29 Thread cokofreedom
a = 1, 2 b = 3, 4, 5 c = 6, 7, 8, 9 coord = list() for i, j, k in zip(a, b, c): coord.append((i, j, k)) print coord -- http://mail.python.org/mailman/listinfo/python-list

Re: defaultdict.fromkeys returns a surprising defaultdict

2008-06-04 Thread cokofreedom
> > No need. The patch would be rejected. It would break existing code > that uses default.fromkeys() as designed and documented. > Perhaps that could be useful, so that future questions or posts on the matter could instantly be directed to the rejected patch? -- http://mail.python.org/mailman/l

Re: Why does python not have a mechanism for data hiding?

2008-06-04 Thread cokofreedom
> > But the leading underscore doesn't tell you whether it is your own > private date, which you can use a you see fit, or those of someone > else, which you have to be very carefull with. > > -- > Antoon Pardon Well how is that different from public accessor and mutators of private variables? --

Re: Newb question: underscore

2008-06-05 Thread cokofreedom
> > My question is: Why would anyone decide to obfuscate something as easy > > to read as Python??? > > They didn't decide to obfuscate; they decided to follow a > strongly-expected convention for the name of that function by existing > users of the 'gettext' functionality, in contexts that predate

Re: Why does python not have a mechanism for data hiding?

2008-06-06 Thread cokofreedom
Someone asked about Java; class FieldTest { public String publicString = "Foobar"; private String privateString = "Hello, World!"; } import java.lang.reflect.Field; public class Test4 { public static void main(String args[]) { final Field fields[] = FieldTest.class.getDecla

Re: Why does python not have a mechanism for data hiding?

2008-06-11 Thread cokofreedom
On Jun 11, 8:11 am, "Russ P." <[EMAIL PROTECTED]> wrote: > On Jun 10, 11:58 am, Jonathan Gardner > > > Who cares what the type of an object is? Only the machine. Being able > > to tell, in advance, what the type of a variable is is a premature > > optimization. Tools like psyco prove that computers

Re: boolian logic

2008-06-13 Thread cokofreedom
> > if var not in (A, B, C): >do_something() > And this is why I love python. -- http://mail.python.org/mailman/listinfo/python-list

Re: dict order

2008-06-18 Thread cokofreedom
On Jun 18, 11:22 am, Robert Bossy <[EMAIL PROTECTED]> wrote: > Hi, > > I wish to know how two dict objects are compared. By browsing the > archives I gathered that the number of items are first compared, but if > the two dict objects have the same number of items, then the comparison > algorithm wa

Re: dict order

2008-06-18 Thread cokofreedom
On Jun 18, 12:32 pm, [EMAIL PROTECTED] wrote: > On Jun 18, 11:22 am, Robert Bossy <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I wish to know how two dict objects are compared. By browsing the > > archives I gathered that the number of items are first compared, but if > > the two dict objects have th

Re: dict order

2008-06-18 Thread cokofreedom
On Jun 18, 4:45 pm, Kirk Strauser <[EMAIL PROTECTED]> wrote: > At 2008-06-18T10:32:48Z, [EMAIL PROTECTED] writes: > > # untested 2.5 > > for keys in dict_one.items(): > > if keys in dict_two: > > if dict_one[keys] != dict_two[keys]: > > # values are different > > else: > > # key i

Re: Simple Python class questions

2008-06-20 Thread cokofreedom
> > Yes I was wondering about that, but I wasn't clear about when 'body' > code (ie not contained within a def block) in the module might run > under Python. So it seemed to be safer to place the import statement > inside the 'constructor' to get the earliest warning of non-visibility > of pyserial

Re: String question

2008-06-23 Thread cokofreedom
On Jun 23, 4:45 pm, Andreu <[EMAIL PROTECTED]> wrote: > I want to split a sentence and assign each word to a variable. > In Ruby I can do it as: > > v1,v2,v3,v4,v5 = str1.split > > Which will be the Python equivalent ? Thanks. > > Andrew. Well a straight copy would be... >>> example = "Hello, how

  1   2   >