How to determine if printing is being a bottleneck in my code?

2012-12-04 Thread SherjilOzair
Hello list,

When it comes to printing things while some computation is being done, there 
are 2 extremes.

1. printing speed is slower than data-to-print generation speed. In this case, 
printing is a bottleneck. Examples: for i in xrange(2**30): print i. Without 
the print, this code would be much faster.

2. data-to-print generation speed is slower than printing speed. So, this case, 
printing does now slow you down much. Example: for m in matrices: print 
m.inverse() # inverse is a time-taking function

These two cases are pretty easy. But, my question is, how to draw the line? How 
do I know that print is slowing me down, and I should probably remove some of 
them? Is there a scientific way to do this, rather than just intuition and 
guesswork?

I can clarify, if needed.
Thanks,
Sherjil Ozair
-- 
http://mail.python.org/mailman/listinfo/python-list


Scoping Issues

2012-05-24 Thread SherjilOzair
def adder():
s = 0
def a(x):
s += x
return sum
return a

pos, neg = adder(), adder()
for i in range(10):
print pos(i), neg(-2*i)

This should work, right? Why does it not?

Checkout slide no. 37 of a Tour of Go to know inspiration. Just wanted to see 
if python was the same as Go in this regard. Sorry, if I'm being rude, or 
anything. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-19 Thread SherjilOzair
Well, if not modify python itself, I was thinking of making another shell, 
which borrows a lot from python, something like merging bash and python. such 
that I can do `cd ~/Desktop/dev` and `for i in open('file.txt'): print i` at 
the some shell. This I think would be VERY useful.

IPyhton is very good, but after all, it is just an advanced interpreter, not a 
default shell. I don't want this to run on top of bash or sh. But it should run 
on its own, at shell level.

Bash and sh, according to me, have very ugly syntaxes and the general user does 
not even use those. Python put on the shell would be adhering to python's 
vision, i.e. bringing programming to the masses.
The general user, who earlier could not do batch operations, and had to buy 
software and such for all that, could now write his open simple python script 
and run it in his shell that would do as he wants.

Python on the shell could effectively remove learning grep, awk, sed, bash and 
the various unix utilities.
Don't take me wrong. Those are awesome tools, and I use them. But the 
awesomeness is not experienced by the general UNIX user on mac or linux. Python 
could do that.

We all know how great a programming language python is. Imagine being able to 
control your computer with such an elegant language. Imagine that I import some 
speech recognition utility on the terminal shell, and voila, I'm speaking to 
the computer and it is doing stuff on the terminal for me.

Shell would give python raw power! And Python would manage it well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python as a default shell, replacement of bash, sh, cmd ?

2012-02-19 Thread SherjilOzair
Well, if not modify python itself, I was thinking of making another shell, 
which borrows a lot from python, something like merging bash and python. such 
that I can do `cd ~/Desktop/dev` and `for i in open('file.txt'): print i` at 
the some shell. This I think would be VERY useful.

IPyhton is very good, but after all, it is just an advanced interpreter, not a 
default shell. I don't want this to run on top of bash or sh. But it should run 
on its own, at shell level.

Bash and sh, according to me, have very ugly syntaxes and the general user does 
not even use those. Python put on the shell would be adhering to python's 
vision, i.e. bringing programming to the masses.
The general user, who earlier could not do batch operations, and had to buy 
software and such for all that, could now write his open simple python script 
and run it in his shell that would do as he wants.

Python on the shell could effectively remove learning grep, awk, sed, bash and 
the various unix utilities.
Don't take me wrong. Those are awesome tools, and I use them. But the 
awesomeness is not experienced by the general UNIX user on mac or linux. Python 
could do that.

We all know how great a programming language python is. Imagine being able to 
control your computer with such an elegant language. Imagine that I import some 
speech recognition utility on the terminal shell, and voila, I'm speaking to 
the computer and it is doing stuff on the terminal for me.

Shell would give python raw power! And Python would manage it well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python as a default shell, replacement of bash, sh, cmd ?

2012-02-18 Thread SherjilOzair
Has it been considered to add shell features to python, such that it can be 
used as a default shell, as a replacement for bash, etc.

I'm sure everyone would agree that doing this would make the terminal very 
powerful.

What are your views on this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Best way to insert sorted in a list

2011-06-17 Thread SherjilOzair
There are basically two ways to go about this.
One is, to append the new value, and then sort the list.
Another is to traverse the list, and insert the new value at the
appropriate position.

The second one's complexity is O(N), while the first one's is O(N *
log N).

Still, the second one works much better, because C code is being used
instead of pythons.

Still, being a programmer, using the first way (a.insert(x);
a.sort()), does not feel right.

What has the community to say about this ? What is the best (fastest)
way to insert sorted in a list ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I want this to work. [[]] * n

2011-06-14 Thread SherjilOzair
Thanks. This works. :)

Regards,
Sherjil Ozair
-- 
http://mail.python.org/mailman/listinfo/python-list


I want this to work. [[]] * n

2011-06-13 Thread SherjilOzair
I want a list which contains n lists, which are all different. I had
read a page which was about the mutability of lists, and how the *
operator on lists just does a shallow copy. But I can't find it now.
Does anyone know of that page ?

Either way, How to get a list of list, with all original lists ?
-- 
http://mail.python.org/mailman/listinfo/python-list