Re: checking if a list is empty

2011-05-06 Thread scattered
On May 6, 2:36 am, Jabba Laci wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: > ... > > Thanks, > > Laszlo is there any problem with (3) if li == []: ? Seems to work when I test it and seem

Re: if statement multiple or

2011-05-06 Thread scattered
On May 6, 8:25 am, Christian Heimes wrote: > Am 06.05.2011 14:09, schrieb scattered: > > > sets could also work > > > if set('abc') & set(line) == set(): > >      print line > > Right! > Sets work in this special case, because the OP just want

Re: if statement multiple or

2011-05-06 Thread scattered
On May 6, 7:00 am, Christian Heimes wrote: > Am 06.05.2011 12:47, schrieb Lutfi Oduncuoglu: > > > Hi, > > > I am trying to write a script and I realised that I need to use something > > like > > > if ('a' or 'b' or 'c')  not in line: > >    print line > > > But it does not work for. What may be th

Re: Hooking into Python's memory management

2011-05-04 Thread scattered
On May 4, 12:51 pm, Daniel Neilson wrote: > Hello, >   I'm hoping that there will be someone here with sufficient expertise > to answer a question on Python 3 for me. > >   I work in the Computer Science department at a large Canadian > University. We are currently doing a feasibility analysis for

Re: Pairwise frequency count from an incidence matrix of group membership

2011-04-22 Thread scattered
On Apr 22, 6:57 am, Jean-Michel Pichavant wrote: > Shafique, M. (UNU-MERIT) wrote: > > Hi, > > I have a number of different groups g1, g2, … g100 in my data. Each > > group is comprised of a known but different set of members (m1, m2, > > …m1000) from the population. The data has been organized in

Re: Feature suggestion -- return if true

2011-04-12 Thread scattered
On Apr 12, 10:05 am, Westley Martínez wrote: > On Tue, 2011-04-12 at 12:44 +1000, Chris Angelico wrote: > > On Tue, Apr 12, 2011 at 12:20 PM, James Mills > > wrote: > > > On Tue, Apr 12, 2011 at 12:18 PM, Jason Swails > > > wrote: > > >> This is only true if n < 5.  Otherwise, the first returns

Re: Feature suggestion -- return if true

2011-04-12 Thread scattered
On Apr 12, 2:21 am, James Mills wrote: > On Tue, Apr 12, 2011 at 4:08 PM, Nobody wrote: > > It should be abundantly clear that this only returns if the expression is > > considered true, otherwise it continues on to the following statements. > > Uggh come on guys. We've been over this. > You cann

Re: a better way to invert a list?

2011-04-06 Thread scattered
On Apr 6, 4:48 am, Glazner wrote: > > > def invert(p): > > >     inverse = [None] * len(p) > > >     for (i, j) in enumerate(p): > > >         inverse[j] = i > > >     return inverse > > > Elegant. This seems like the best solution, although it isn't as much > > fun to write as a "one-liner". Than

Re: a better way to invert a list?

2011-04-05 Thread scattered
On Apr 5, 5:46 pm, Ian Kelly wrote: > On Tue, Apr 5, 2011 at 3:17 PM, scattered wrote: > > Greetings, > > > I've been playing around (in Python 3.1) with permutations of > > 0,1,...,n-1, represented by lists, p, of length n, where p[i] = the > > image of i un

a better way to invert a list?

2011-04-05 Thread scattered
Greetings, I've been playing around (in Python 3.1) with permutations of 0,1,...,n-1, represented by lists, p, of length n, where p[i] = the image of i under the permutation. I wanted to be able to calculate the inverse of such a permutation, and came up with the following succint but not quite re

Re: dynamic assigments

2011-03-25 Thread scattered
On Mar 25, 1:44 am, Steven D'Aprano wrote: > > In my earlier post, I described the dynamic creation of variables as: > > "... something you should *nearly* always avoid doing." [Emphasis added.] > > Congratulations, you've found one of the few exceptions. Of course an > interactive shell must allo

Re: dynamic assigments

2011-03-25 Thread scattered
On Mar 24, 11:08 pm, Tim Leslie wrote: > On 25 March 2011 13:51, scattered wrote: > > > Here is another possibility: you are using Python *interactively* in > > solving cryptograms (as a matter of fact - I was doing exactly this > > yesterday in trying to solve some Playf

Re: dynamic assigments

2011-03-24 Thread scattered
On Mar 24, 10:51 pm, scattered wrote: [snip] > I can easily imagine other > situations in which a user might want to create a large number of > bindings for interactive use. Maybe as a teacher (I'm a math teacher) > you have written a student-class which contains thing

Re: dynamic assigments

2011-03-24 Thread scattered
On Mar 24, 7:18 pm, Steven D'Aprano wrote: > On Thu, 24 Mar 2011 14:39:34 -0700, scattered wrote: > > Could try: > > >>>> my_list = [("x", 7), ("y", 8)] > >>>> for pair in my_list: exec(pair[0] + " = " + str(pair[1]))

Re: dynamic assigments

2011-03-24 Thread scattered
On Mar 24, 2:39 pm, Seldon wrote: > Hi, I have a question about generating variable assignments dynamically. > > I have a list of 2-tuples like this > > ( > (var1, value1), > (var2, value2), > .. , > ) > > where var1, var2, ecc. are strings and value1, value2 are generic objects. > > Now, I would

Re: possible to run a python script without installing python?

2011-03-15 Thread scattered
On Mar 15, 4:58 pm, davidj411 wrote: > it seems that if I copy the python.exe binary and the folders > associated with it to a server without python, i can run python. > does anyone know which files are important to copy and which can be > omitted? > > i know about py2exe and have had no luck with

Re: I found some very odd behaviour in Python's very basic types

2011-03-10 Thread scattered
On Mar 10, 12:47 am, Sunjay Varma wrote: > For some reason, sub-classing and overwriting a built-in type does not > change the behavior of the literal. Logically speaking, overwriting a > name, such as str, should delete the basic str type, and replace it > with the new class or object put in its

Re: Running Scripts vs Interactive mode

2011-02-24 Thread scattered
On Feb 23, 5:22 pm, grobs456 wrote: > Hi, > > I am trying to work through the tutorial at:http://docs.python.org/tutorial/ > > The issue I am facing is with regards to the discussion about > "Invoking the Interpreter" and "Executable Python Scripts". It was > rather hazy in my opinion. > > see:htt

Re: simple games w/o pygame

2010-12-22 Thread scattered
On Dec 22, 11:40 am, William Gill wrote: > I am teaching an 11 year old who wants to learn programming.  I chose > Python, and it is working well.  I seem to remember lots of simple > script games, like quizzes, number games etc. that would be good for his > tutorial.  However, now all I can find

Re: Scheme as a virtual machine?

2010-11-22 Thread scattered
On Nov 22, 9:45 am, Raffael Cavallaro wrote: > On 2010-11-22 08:12:27 -0500, markhanif...@gmail.com said: > > > All opinions are biased. > > All opinions show some bias. Not all opinions represent what is usually > called a "conflict of interest." Since JH makes his living selling > tools and trai

Re: Is Python like VB?

2005-03-18 Thread scattered
with Excel. For now I think I will stick to my goal of learning things like Chaco and wxPython. If I ever take the Linux plunge it's nice to know that OpenOffice is closing the gap with Excel as far as programmability is concerned. -scattered -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python like VB?

2005-03-18 Thread scattered
ke statistical simulations. I liked the ability to get functioning code quickly in VBA, together with the ability to easily generate graphs of the results, etc., but I finally got tired of the slow speed and verbose syntax. I'm hoping that Python (as packaged by Enthought together with variou