[Tutor] multiply and sum two lists with list comprehension?

2010-01-27 Thread Muhammad Ali
Hi, I am multipliying two lists so that each of list As elements get multiplied to the corresponding list Bs. Then I am summing the product. For example, A= [1, 2, 3] and B=[2, 2, 2] so that I get [2, 4, 6] after multiplication and then sum it to get 12. I can do it using map like this: sum(map(

[Tutor] Pythonify this code!

2009-07-13 Thread Muhammad Ali
Hi, This is my first attempt at python. I tried my hand at steganography for fun. The code includes separate, combine, encode, decode functions. The separate function takes a number and it's base and returns a list containing each digit of the number in a list, vice versa for combine. The encode f

Re: [Tutor] Pythonify this code!

2009-07-14 Thread Muhammad Ali
Hi everyone, Thanks for the comments Dave and Alan! Based on these I have updated the code... I don't know if this is more readable. @Dave: I kept the original separate and combine function with bases as I thought I would move them to a math library if I need to work in other bases, however now

Re: [Tutor] Can't transform a list of tokens into a text

2009-07-15 Thread Muhammad Ali
Try changing all instances of list[i + 1] to list[i] On Thu, Jul 16, 2009 at 8:33 AM, Eduardo Vieira wrote: > #=== > I tried this version to post in this forum but that gives me an error. > I don't know why I don't get an error with the code above which is > essentially the same: > # -*- coding:

[Tutor] Mapping of co-ordinates... pygame

2009-07-23 Thread Muhammad Ali
Hi, I have some x and y co-ordinates ranging from (-100, 100) for each x and y. Something like this: 100 | | | | -100--100 |

Re: [Tutor] Mapping of co-ordinates... pygame

2009-07-23 Thread Muhammad Ali
Thanks Wayne and Alan, Here is what I finally ended up with: def newCoord(x, y, oldWidth, oldHeight, newWidth, newHeight): return( newWidth/2 + newWidth/oldWidth * x), (newHeight/2 - newHeight/oldHeight * y) for my earlier example, the old width and height would be 200, 200 respectively. Th

Re: [Tutor] [pygame] why does my window not close?

2009-08-03 Thread Muhammad Ali
Hi, I have the same problem running pygame programs from the interpreter. I now just put a shebang line on top of the script like #!/usr/bin/env python and do chmod +x on the script and then run it from the terminal by doing ./script.py or double clicking on the file. It works fine when run dire

Re: [Tutor] nonlinear fittinig

2009-08-03 Thread Muhammad Ali
Don't know about nlinfit but you can check numpy, scipy and matplotlib that provide matlab like functionality. Ali On Mon, Aug 3, 2009 at 11:20 PM, Alireza Alemi wrote: > Dear All > > I am not sure if here is the right place to ask this question. > Anyway, the question is: Is there a pythonic

Re: [Tutor] Scope of exceptions

2009-08-05 Thread Muhammad Ali
Instead of putting it in every function, you could probably do it once in your "main" function that does all the work... On Wed, Aug 5, 2009 at 4:34 PM, Craig McDonald wrote: > Howdy, > > I am in the process of moving all my perl scripts to python and also > trying to learn to program rather than