A way to re-organize a list

2007-07-19 Thread beginner
Hi Everyone, I have a simple list reconstruction problem, but I don't really know how to do it. I have a list that looks like this: l=[ ("A", "a", 1), ("A", "a", 2), ("A", "a", 3), ("A", "b", 1), ("A", "b", 2), ("B", "a", 1), ("B", "b", 1)] What I want to do is to reorganize it in groups, first

Flatten a list/tuple and Call a function with tuples

2007-07-25 Thread beginner
Hi, I am wondering how do I 'flatten' a list or a tuple? For example, I'd like to transform[1, 2, (3,4)] or [1,2,[3,4]] to [1,2,3,4]. Another question is how do I pass a tuple or list of all the aurgements of a function to the function. For example, I have all the arguments of a function in a tu

Re: Flatten a list/tuple and Call a function with tuples

2007-07-25 Thread beginner
On Jul 25, 10:19 am, Stargaming <[EMAIL PROTECTED]> wrote: > On Wed, 25 Jul 2007 14:50:18 +, beginner wrote: > > Hi, > > > I am wondering how do I 'flatten' a list or a tuple? For example, I'd > > like to transform[1, 2, (3,4)] or [1,2,[3,4]] to

Re: Flatten a list/tuple and Call a function with tuples

2007-07-25 Thread beginner
On Jul 25, 11:00 am, [EMAIL PROTECTED] wrote: > On Jul 25, 10:46 am, beginner <[EMAIL PROTECTED]> wrote: > > > > > > > On Jul 25, 10:19 am, Stargaming <[EMAIL PROTECTED]> wrote: > > > > On Wed, 25 Jul 2007 14:50:18 +, beginner wrote: > >

Re: Flatten a list/tuple and Call a function with tuples

2007-07-25 Thread beginner
> Not the most beautiful solution, but it works. > > Diez- Hide quoted text - > > - Show quoted text - Yeah it works! Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Flatten a list/tuple and Call a function with tuples

2007-07-25 Thread beginner
> Also, this has not been suggested: > > py> def g(): > ... return (1,2) > ... > py> def f(a,b,c): > ... return a+b+c > ... > py> f(c=10, *g()) > 13 > > James- Hide quoted text - > > - Show quoted text - Great idea. -- http://mail.python.org/mailman/listinfo/python-list

Re: Flatten a list/tuple and Call a function with tuples

2007-07-25 Thread beginner
On Jul 25, 11:33 am, Paul Rubin <http://[EMAIL PROTECTED]> wrote: > beginner <[EMAIL PROTECTED]> writes: > > I know the * operator. However, a 'partial unpack' does not seem to work. > > A few other posters have mentioned ways around this, but you might ask &

Re: Flatten a list/tuple and Call a function with tuples

2007-07-25 Thread beginner
> Well, there are several ways to solve this. You could either invoke f(*g > () + (10,)). Might be a bit nasty and unreadable, though. Or you could > just change your function f to accept them in reversed order (f(10, *g) > should work) or convert g() to return a dictionary like {'b': 1, 'c': 2} >

Another C API Question

2007-07-26 Thread beginner
number? Thanks, beginner -- http://mail.python.org/mailman/listinfo/python-list

C API -- Two questions

2007-07-26 Thread beginner
Hi Everyone, I am writing a C extension and encountered two problems. 1) How can I include a description of the arguments? I can include a description string. No problem. But whenever I say help(my_func) it shows the arguments are "... ". However, if a function is defined in python, I will defini

Re: Another C API Question

2007-07-27 Thread beginner
Hi Farshid, On Jul 26, 8:18 pm, Farshid Lashkari <[EMAIL PROTECTED]> wrote: > beginner wrote: > > I know obj is a number, but I do not know the exact type. How can I > > convert it to double without writing a giant switch() that exhausts > > every single type o

Re: Another C API Question

2007-07-27 Thread beginner
Hi Robert, On Jul 26, 8:16 pm, Robert Kern <[EMAIL PROTECTED]> wrote: > beginner wrote: > > Hi, > > > I run into another C API question. What is the simplest way to convert > > an PyObject into a double? > > > For example, I have > > > PyObject

Re: Another C API Question

2007-07-27 Thread beginner
On Jul 27, 11:37 am, Farshid Lashkari <[EMAIL PROTECTED]> wrote: > beginner wrote: > > This works with PyFloat only. It does not work with integers. > > Did you try it out? I have used it on ints, bools, and objects that > implement the __float__ method. It does not work o

Re: C API -- Two questions

2007-07-27 Thread beginner
On Jul 27, 1:23 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Fri, 27 Jul 2007 00:34:22 +, beginner wrote: > > 2) How can I make the arguments less picky without writing a lot of > > type conversion code? My function really needs a tuple as i

Tkinter program with a usable interpreter console

2007-07-27 Thread beginner
_key_data() >>> update_gui() and my gui is modified for me. The problem is that the Tkinter program ends with a .mainloop() call and it is not going to give back control to the command prompt. I feel it is almost like I need to implement the python shell myself. Is there any better way of doing this?

Tkinter -- Show Data in an Excel like Read-Only Grid

2007-07-27 Thread beginner
implementing this? Thanks, beginner -- http://mail.python.org/mailman/listinfo/python-list

Re: Another C API Question

2007-07-27 Thread beginner
On Jul 27, 4:50 pm, Farshid Lashkari <[EMAIL PROTECTED]> wrote: > beginner wrote: > > I did and it did not seem to work. I ended up doing the following. > > Verbose, isn't it? > > If I do d=PyFloat_AsDouble(oDiscount); in the third "if", I get an &

Re: Another C API Question

2007-07-27 Thread beginner
On Jul 27, 4:50 pm, Farshid Lashkari <[EMAIL PROTECTED]> wrote: > beginner wrote: > > I did and it did not seem to work. I ended up doing the following. > > Verbose, isn't it? > > If I do d=PyFloat_AsDouble(oDiscount); in the third "if", I get an &

Re: Tkinter -- Show Data in an Excel like Read-Only Grid

2007-07-28 Thread beginner
On Jul 27, 11:08 pm, Zentrader <[EMAIL PROTECTED]> wrote: > On Jul 27, 2:56 pm, beginner <[EMAIL PROTECTED]> wrote: > > > Hi All, > > > I am really new to Tk and Tkinter. I googled the web but it was not > > mentioned how to build a data grid with Tkinter. &

Re: Tkinter program with a usable interpreter console

2007-07-28 Thread beginner
On Jul 27, 6:17 pm, Ivan Johansen <[EMAIL PROTECTED]> wrote: > beginner wrote: > > The problem is that the Tkinter program ends with a .mainloop() call > > and it is not going to give back control to the command prompt. I feel > > it is almost like I need to implement

What is the "functional" way of doing this?

2007-07-30 Thread beginner
Hi, If I have a number n and want to generate a list based on like the following: def f(n): l=[] while n>0: l.append(n%26) n /=26 return l I am wondering what is the 'functional' way to do the same. Thanks, beginner -- http://mail.python.org/mai

Re: What is the "functional" way of doing this?

2007-07-31 Thread beginner
On Jul 30, 5:48 pm, beginner <[EMAIL PROTECTED]> wrote: > Hi, > > If I have a number n and want to generate a list based on like the > following: > > def f(n): > l=[] > while n>0: > l.append(n%26) > n /=26 > return l >

standalone process to interact with the web

2007-07-31 Thread beginner
Hi Everyone, I am looking for a way to allow a standalone python process to easily interactive with a few web pages. It has to be able to easily receive requests from the web and post data to the web. I am thinking about implementing a standalone soap server, but I am not sure which library is go

Re: standalone process to interact with the web

2007-07-31 Thread beginner
Hi Steve, On Jul 31, 11:42 am, Steve Holden <[EMAIL PROTECTED]> wrote: > beginner wrote: > > Hi Everyone, > > > I am looking for a way to allow a standalone python process to easily > > interactive with a few web pages. It has to be able to easily receive > >

Re: standalone process to interact with the web

2007-07-31 Thread beginner
On Jul 31, 1:11 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > beginner wrote: > > Hi Steve, > > > On Jul 31, 11:42 am, Steve Holden <[EMAIL PROTECTED]> wrote: > >> beginner wrote: > >>> Hi Everyone, > >>> I am looking for a way to all

Re: A way to re-organize a list

2007-07-31 Thread beginner
On Jul 19, 10:05 am, beginner <[EMAIL PROTECTED]> wrote: > Hi Everyone, > > I have a simple list reconstruction problem, but I don't really know > how to do it. > > I have a list that looks like this: > > l=[ ("A", "a", 1), ("A", &qu

Python end of file marker similar to perl's __END__

2007-07-31 Thread beginner
Hi All, This is just a very simple question about a python trick. In perl, I can write __END__ in a file and the perl interpreter will ignore everything below that line. This is very handy when testing my program. Does python have something similar? Thanks, Geoffrey -- http://mail.python.org/m

Re: Python end of file marker similar to perl's __END__

2007-08-01 Thread beginner
On Jul 31, 10:53 pm, beginner <[EMAIL PROTECTED]> wrote: > Hi All, > > This is just a very simple question about a python trick. > > In perl, I can write __END__ in a file and the perl interpreter will > ignore everything below that line. This is very handy when testing m

Assertion in list comprehension

2007-08-01 Thread beginner
Hi, Does anyone know how to put an assertion in list comprehension? I have the following list comprehension, but I want to use an assertion to check the contents of rec_stdl. I ended up using another loop which essentially duplicates the functions of list comprehension. It just look like a waste o

Awkward format string

2007-08-01 Thread beginner
Hi, In order to print out the contents of a list, sometimes I have to use very awkward constructions. For example, I have to convert the datetime.datetime type to string first, construct a new list, and then send it to print. The following is an example. x=(e[0].strftime("%Y-%m-%d"), e[1]

Re: Awkward format string

2007-08-01 Thread beginner
On Aug 1, 11:31 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On 8/1/07, beginner <[EMAIL PROTECTED]> wrote: > > > Hi, > > > In order to print out the contents of a list, sometimes I have to use > > very awkward constructions. For example, I

Re: Assertion in list comprehension

2007-08-01 Thread beginner
On Aug 1, 11:09 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > On Aug 1, 9:37 am, beginner <[EMAIL PROTECTED]> wrote: > > > > > > > Hi, > > > Does anyone know how to put an assertion in list comprehension? I have > > the fo

Re: Assertion in list comprehension

2007-08-01 Thread beginner
On Aug 1, 11:28 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On 8/1/07, beginner <[EMAIL PROTECTED]> wrote: > > > > > > > Hi, > > > Does anyone know how to put an assertion in list comprehension? I have > > the following list c

Re: Assertion in list comprehension

2007-08-01 Thread beginner
On Aug 1, 12:35 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On 8/1/07, beginner <[EMAIL PROTECTED]> wrote: > > > > > > > On Aug 1, 11:28 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > > > On 8/1/07, beginner <[EMAIL

Re: Assertion in list comprehension

2007-08-01 Thread beginner
On Aug 1, 12:38 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > On 01 Aug 2007 16:55:53 GMT, Stargaming <[EMAIL PROTECTED]> wrote: > > > > > > > On Wed, 01 Aug 2007 11:28:48 -0500, Chris Mellon wrote: > > > > On 8/1/07, beginner <[EMAI

Re: A way to re-organize a list

2007-08-01 Thread beginner
On Aug 1, 1:31 am, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Wed, 01 Aug 2007 01:33:49 +, beginner wrote: > > On Jul 19, 10:05 am, beginner <[EMAIL PROTECTED]> wrote: > >> Hi Everyone, > > >> I have a simple list reconstructio

Re: standalone process to interact with the web

2007-08-02 Thread beginner
On Aug 1, 3:50 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > beginner wrote: > > Hi Everyone, > > > I am looking for a way to allow a standalone python process to easily > > interactive with a few web pages. It has to be able to easily receive > &

Re: standalone process to interact with the web

2007-08-02 Thread beginner
On Aug 1, 5:04 am, Bruno Desthuilliers wrote: > beginner a écrit : > (snip) > > > Yes exactly. I just don't want to reinvent the wheel as I imagine > > there are already tons of libraries and frameworks that support RPC or > > the like functions. > > Why

Re: Awkward format string

2007-08-02 Thread beginner
On Aug 2, 3:32 am, Bruno Desthuilliers wrote: > beginner a écrit : > > > Hi, > > > In order to print out the contents of a list, sometimes I have to use > > very awkward constructions. For example, I have to convert the > > datetime.datetime type to string first,

Re: Efficient Rank Ordering of Nested Lists

2007-08-02 Thread beginner
On Aug 2, 8:20 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > A naive approach to rank ordering (handling ties as well) of nested > lists may be accomplished via: > >def rankLists(nestedList): > def rankList(singleList): > sortedList = list(singleList) > sortedLi

Re: Help me!!

2007-08-16 Thread beginner
> Some one help me so that > If ab = [a,b,c,d] > and cd = [a,c] > my global list file should be [A,b,C,d] If there is a lot of entries in the list, I would consider using an indexed data structure such as dict. >>> ab=['a','b','c','d'] >>> cd=['a','c'] >>> common=[x.upper() for x in ab if x in c

Re: Help me!!

2007-08-16 Thread beginner
On Aug 16, 2:26 pm, beginner <[EMAIL PROTECTED]> wrote: > > Some one help me so that > > If ab = [a,b,c,d] > > and cd = [a,c] > > my global list file should be [A,b,C,d] If there is a lot of entries in the list, I would consider using an indexed data structure such

How to say $a=$b->{"A"} ||={} in Python?

2007-08-16 Thread beginner
Hi All. I'd like to do the following in more succint code: if k in b: a=b[k] else: a={} b[k]=a a['A']=1 In perl it is just one line: $a=$b->{"A"} ||={}. Thanks, Geoffrey -- http://mail.python.org/mailman/listinfo/python-list

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-16 Thread beginner
On Aug 16, 5:43 pm, [EMAIL PROTECTED] (Lawrence Oluyede) wrote: > beginner <[EMAIL PROTECTED]> wrote: > > I'd like to do the following in more succint code: > > > if k in b: > > a=b[k] > > else: > > a={} > > b[k]=a > > b.setde

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-16 Thread beginner
On Aug 16, 6:21 pm, James Stroud <[EMAIL PROTECTED]> wrote: > beginner wrote: > > Hi All. > > > I'd like to do the following in more succint code: > > > if k in b: > > a=b[k] > > else: > > a={} > > b[k]=a > > >

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-16 Thread beginner
On Aug 16, 9:32 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > On Fri, 2007-08-17 at 00:53 +, beginner wrote: > > $b is supposed to be a hash-table of hash-table. If a key exists in > > $b, it points to another hash table. The $a=$b->{"A"} ||={} pattern

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-16 Thread beginner
On Aug 16, 5:35 pm, beginner <[EMAIL PROTECTED]> wrote: > Hi All. > > I'd like to do the following in more succint code: > > if k in b: > a=b[k] > else: > a={} > b[k]=a > > a['A']=1 > > In perl it is just one line: $a=$b->

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-17 Thread beginner
On Aug 17, 2:35 am, Sébastien Buchoux <[EMAIL PROTECTED]> wrote: > beginner a écrit : > > > > > Hi All. > > > I'd like to do the following in more succint code: > > > if k in b: > > a=b[k] > > else: > > a={} > >

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-17 Thread beginner
On Aug 16, 11:02 pm, "Carsten Haese" <[EMAIL PROTECTED]> wrote: > On Fri, 17 Aug 2007 03:15:10 -, beginner wrote > > > On Aug 16, 9:32 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > > > What is the best solution in Perl need not be the best solution

How to call module functions inside class instance functions?

2007-08-18 Thread beginner
Hi Everyone, I have encountered a small problems. How to call module functions inside class instance functions? For example, calling func1 in func2 resulted in a compiling error. "my module here" def func1(): print "hello" class MyClass: def func2(): #how can I call func1 her

How to make a module function visible only inside the module?

2007-08-18 Thread beginner
Hi Everyone, Is there any equivalent version of C's static function in Python. I know I can make a class function private by starting a function name with two underscores, but it does not work with module functions. For exmaple, __func1 is still visible outside the module. mymodule.py """my modu

Re: Parser Generator?

2007-08-18 Thread beginner
On Aug 18, 5:22 pm, "Jack" <[EMAIL PROTECTED]> wrote: > Hi all, I need to do syntax parsing of simple naturual languages, > for example, "weather of London" or "what is the time", simple > things like these, with Unicode support in the syntax. > > In Java, there are JavaCC, Antlr, etc. I wonder wha

"constructor" or initialization function for module

2007-08-18 Thread beginner
Hi Everyone, An extended module (.pyd) written in C have an init function that is called when the module is imported. Does anyone know if there is a way to provide an init function for a module written in python? Thanks, Geoffrey -- http://mail.python.org/mailman/listinfo/python-list

Re: How to call module functions inside class instance functions?

2007-08-18 Thread beginner
On Aug 18, 8:18 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > beginner wrote: > > Hi Everyone, > > > I have encountered a small problems. How to call module functions > > inside class instance functions? For example, calling func1 in func2 > > resulted in a co

Re: How to call module functions inside class instance functions?

2007-08-18 Thread beginner
On Aug 18, 8:13 pm, Zentrader <[EMAIL PROTECTED]> wrote: > On Aug 18, 5:40 pm, beginner <[EMAIL PROTECTED]> wrote: > > > > > > > Hi Everyone, > > > I have encountered a small problems. How to call module functions > > inside class insta

Re: "constructor" or initialization function for module

2007-08-18 Thread beginner
On Aug 18, 8:25 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > beginner wrote: > > Hi Everyone, > > > An extended module (.pyd) written in C have an init function that is > > called when the module is imported. Does anyone know if there is a way > > to provide a

Re: How to make a module function visible only inside the module?

2007-08-18 Thread beginner
On Aug 18, 8:27 pm, [EMAIL PROTECTED] (Lawrence Oluyede) wrote: > beginner <[EMAIL PROTECTED]> wrote: > > Is there any equivalent version of C's static function in Python. I > > know I can make a class function private by starting a function name > > with two unders

Re: How to make a module function visible only inside the module?

2007-08-19 Thread beginner
On Aug 19, 7:45 am, Bjoern Schliessmann wrote: > beginner wrote: > > Thanks a lot. I was using two underscores, __module_method() as my > > static method convention, and then I had some problems calling > > them from inside class methods. > > *Please* do yourself and

'REPL' style IDE

2007-08-20 Thread beginner
Hi Everyone, I am using the Wing IDE. It works great when developing applications, but the workflow is like Visual Studio -- after you execute it or debug it, the python script ends. What I want is an interactive interpreting environment. I want the IDE to execute a boot script to initialize my e

Re: 'REPL' style IDE

2007-08-20 Thread beginner
On Aug 20, 12:50 pm, beginner <[EMAIL PROTECTED]> wrote: > Hi Everyone, > > I am using the Wing IDE. It works great when developing applications, > but the workflow is like Visual Studio -- after you execute it or > debug it, the python script ends. > > What I want is

Re: str().join() isn't working

2007-08-20 Thread beginner
On Aug 20, 1:16 pm, "Robert Dailey" <[EMAIL PROTECTED]> wrote: > here is a more realized example of the lists I'm trying to join: > > _user_includes = [ > "../src", > "../resource", > "../inc", > "../src", > "../data", > "../gui", > "../script

Re: 'REPL' style IDE

2007-08-20 Thread beginner
On Aug 20, 2:51 pm, JoeSox <[EMAIL PROTECTED]> wrote: > On 8/20/07, beginner <[EMAIL PROTECTED]> wrote: > > > Hi Everyone, > > > I am using the Wing IDE. It works great when developing applications, > > but the workflow is like Visual Studio -- after you

Re: 'REPL' style IDE

2007-08-20 Thread beginner
On Aug 20, 2:39 pm, Jeff <[EMAIL PROTECTED]> wrote: > python-mode in Emacs. Yeah, but I don't know anything about Emacs and as far as I know it is pretty complicated. -- http://mail.python.org/mailman/listinfo/python-list

List Comprehension Question: One to Many Mapping?

2007-08-23 Thread beginner
Hi All, How do I map a list to two lists with list comprehension? For example, if I have x=[ [1,2], [3,4] ] What I want is a new list of list that has four sub-lists: [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]] [1,2] is mapped to [1,2] and [f(1), f(2)] and [3,4] is mapped to [3,4], [f(3), f(4)]

Re: List Comprehension Question: One to Many Mapping?

2007-08-23 Thread beginner
On Aug 24, 12:41 am, Davo <[EMAIL PROTECTED]> wrote: > On Aug 23, 9:24 pm, beginner <[EMAIL PROTECTED]> wrote: > > > > > > > Hi All, > > > How do I map a list to two lists with list comprehension? > > > For example, if I have x=[ [1,2], [3,4] ]

Re: List Comprehension Question: One to Many Mapping?

2007-08-24 Thread beginner
On Aug 24, 12:44 am, beginner <[EMAIL PROTECTED]> wrote: > On Aug 24, 12:41 am, Davo <[EMAIL PROTECTED]> wrote: > > > > > > > On Aug 23, 9:24 pm, beginner <[EMAIL PROTECTED]> wrote: > > > > Hi All, > > > > How do I map a list to t

Re: List Comprehension Question: One to Many Mapping?

2007-08-24 Thread beginner
On Aug 24, 5:47 am, Paul Rubin wrote: > Boris Borcic <[EMAIL PROTECTED]> writes: > > >> For example, if I have x=[ [1,2], [3,4] ] > > > >> What I want is a new list of list that has four sub-lists: > > > >> [[1,2], [f(1), f(2)], [3,4], [f(3), f(4)]] > > > [[a, map(f,a)] f

Re: Joining Big Files

2007-08-25 Thread beginner
On Aug 25, 4:57 am, mosscliffe <[EMAIL PROTECTED]> wrote: > I have 4 text files each approx 50mb. > > I need to join these into one large text file. > > I only need to do this very occasionally, as the problem has occurred > because of upload limitations. > > Bearing in mind filesize and memory use

Re: List Comprehension Question: One to Many Mapping?

2007-09-14 Thread beginner
On Aug 24, 5:35 am, Boris Borcic <[EMAIL PROTECTED]> wrote: > Paul Rubin wrote: > > beginner <[EMAIL PROTECTED]> writes: > >> For example, if I have x=[ [1,2], [3,4] ] > > >> What I want is a new list of list that has four sub-lists: > > >> [[1

Speed of Nested Functions & Lambda Expressions

2007-10-23 Thread beginner
Hi All, It is really convenient to use nested functions and lambda expressions. What I'd like to know is if Python compiles fn_inner() only once and change the binding of v every time fn_outer() is called or if Python compile and generate a new function object every time. If it is the latter, will

Life-time of temporary variables in list comprehensions

2007-10-23 Thread beginner
Hi All, If I have a list comprehension: ab=["A","B"] c = "ABC" [1.0 if c=='A' else c='B' for c in ab] print c >>"B" My test shows that if c is not defined before the list comprehension, it will be created in the list comprehension; if it is defined before the list comprehension, the value will

Re: Life-time of temporary variables in list comprehensions

2007-10-23 Thread beginner
On Oct 23, 12:02 pm, beginner <[EMAIL PROTECTED]> wrote: > Hi All, > > If I have a list comprehension: > > ab=["A","B"] > c = "ABC" > [1.0 if c=='A' else c='B' for c in ab] > print c > > >>"B"

Re: Speed of Nested Functions & Lambda Expressions

2007-10-23 Thread beginner
On Oct 23, 11:06 am, Gary Herron <[EMAIL PROTECTED]> wrote: > beginner wrote: > > Hi All, > > > It is really convenient to use nested functions and lambda > > expressions. What I'd like to know is if Python compiles fn_inner() > > only once and change

Re: Speed of Nested Functions & Lambda Expressions

2007-10-24 Thread beginner
On Oct 24, 2:52 am, Duncan Booth <[EMAIL PROTECTED]> wrote: > beginner <[EMAIL PROTECTED]> wrote: > > It is really convenient to use nested functions and lambda > > expressions. What I'd like to know is if Python compiles fn_inner() > > only once and chang

Re: Better writing in python

2007-10-24 Thread beginner
On Oct 24, 9:04 am, "A.T.Hofkamp" <[EMAIL PROTECTED]> wrote: > > On 2007-10-24, Alexandre Badez <[EMAIL PROTECTED]> wrote: > > I'm just wondering, if I could write a in a "better" way this > > code > > > lMandatory = [] > > lOptional = [] > > for arg in cls.dArguments: > > if arg is True: > >

Handle Exceptions Inside List Comprehension

2007-10-29 Thread beginner
Hi All, I am wondering if there is any way to handle exceptions inside list comprehension. For example, [f(x) for x in xs] I want to skip the point if f(x) raises an exception. How can I do that without totally removing the list comprehension? Thanks, Geoffrey -- http://mail.python.org/mailma

Inefficient summing

2008-10-08 Thread beginner
Hi All, I have a list of records like below: rec=[{"F1":1, "F2":2}, {"F1":3, "F2":4} ] Now I want to write code to find out the ratio of the sums of the two fields. One thing I can do is: sum(r["F1"] for r in rec)/sum(r["F2"] for r in rec) But this is slow because I have to iterate through th

Re: split a list based on a predicate

2008-10-09 Thread beginner
Hi, On Oct 8, 6:36 pm, "Rajanikanth Jammalamadaka" <[EMAIL PROTECTED]> wrote: > Hi! > > Is there a functional way to do this? > > I have an array [0,1,2,3,0,1,2,2,3] and I want the first chunk of > non-decreasing values from this array (eg: In this case I want > [0,1,2,3]) > > Thanks, > > Rajanika

Re: Inefficient summing

2008-10-09 Thread beginner
On Oct 9, 3:53 pm, Alexander Schmolck <[EMAIL PROTECTED]> wrote: > beginner <[EMAIL PROTECTED]> writes: > > Hi All, > > > I have a list of records like below: > > > rec=[{"F1":1, "F2":2}, {"F1":3, "F2":4} ] > &g

How to write simple code to match strings?

2009-12-29 Thread beginner
Hi All, I run into a problem. I have a string s that can be a number of possible things. I use a regular expression code like below to match and parse it. But it looks very ugly. Also, the strings are literally matched twice -- once for matching and once for extraction -- which seems to be very s

Re: How to write simple code to match strings?

2009-12-29 Thread beginner
Hi Steve, On Dec 30, 12:01 am, Steven D'Aprano wrote: > On Tue, 29 Dec 2009 21:01:05 -0800, beginner wrote: > > Hi All, > > > I run into a problem.  I have a string s that can be a number of > > possible things. I use a regular expression code like below to match a

Question

2005-08-28 Thread Beginner/Not Yet Programmer
I've never programmed before, so I thought I'd try and learn a bit by using some Python tutorials. I started using the tutorial at http://www.honors.montana.edu/~jjc/easytut/easytut/node3.html. It mentioned different forms of Python, specifically Command Line and IDLE. Being inexperienced, I'm n