On 01/13/2013 07:45 AM, subhabangal...@gmail.com wrote:
Dear Group,
I have a list like,
list1=[1,2,3,4,5,6,7,8,9,10,11,12]
Now, if I want to take a slice of it, I can.
It may be done in,
list2=list1[:3]
print list2
[1, 2, 3]
If I want to iterate the list, I may do as,
for i in list1:
On 01/13/13 07:48, Boris FELD wrote:
2013/1/13 Tim Chase :
SIZE = 3
for i in range(len(list1)//SICE):
... print list1[i*SIZE:i*SIZE+SIZE]
A little shorter and simpler version:
x = x[1:]
for i in range(0,len(x),SIZE):
... print x[i: i+SIZE]
Doh, I always forget that range() takes
2013/1/13 Tim Chase :
> On 01/13/13 06:45, subhabangal...@gmail.com wrote:
>
SIZE = 3
for i in range(len(list1)//SICE):
> ... print list1[i*SIZE:i*SIZE+SIZE]
> ...
> [1, 2, 3]
> [4, 5, 6]
> [7, 8, 9]
> [10, 11, 12]
>
A little shorter and simpler version:
>>> x = x[1:]
>>> for i in ra
On 01/13/13 06:45, subhabangal...@gmail.com wrote:
Dear Group,
I have a list like,
list1=[1,2,3,4,5,6,7,8,9,10,11,12]
Now, if I want to take a slice of it, I can.
It may be done in,
list2=list1[:3]
print list2
[snip]
Now, I want to combine iterator with a slicing condition like
for i=li
On 01/13/2013 07:45 AM, subhabangal...@gmail.com wrote:
> Dear Group,
>
> I have a list like,
>
list1=[1,2,3,4,5,6,7,8,9,10,11,12]
What version of Python?
> Now, if I want to take a slice of it, I can.
> It may be done in,
list2=list1[:3]
print list2
> [1, 2, 3]
>
> If I want to it
Dear Group,
I have a list like,
>>> list1=[1,2,3,4,5,6,7,8,9,10,11,12]
Now, if I want to take a slice of it, I can.
It may be done in,
>>> list2=list1[:3]
>>> print list2
[1, 2, 3]
If I want to iterate the list, I may do as,
>>> for i in list1:
print "Iterated Value Is:",i
It
I assume this is one of the addons for Python. I know that there
is a great deal of stuff out there available for Python that does
some of the stuff that I am looking at, but I am interested in
learning to use Python. When I want to get faster and more
general, I will get some of this stuff or us
I did appreciate the reference. I started with Fortran
on an IBM (7040 maybe, not sure) using keypunched cards. Some of the
concepts of the newer languages take some to seem useable.
Jim
--
http://mail.python.org/mailman/listinfo/python-list
Jim wrote:
> Wow! All I wanted to do was write the equivalence
> of the Fortran statement: Real*4 matrix(n,n).
If you are doing numerical linear algebra in Python, you should use the
Numeric or Numarray modules. With Numeric, the equivalent is just
from Numeric import zeros
matrix = zeros([n,n]
Wow! All I wanted to do was write the equivalence
of the Fortran statement: Real*4 matrix(n,n).
I'm going to have to go to the intrepreter to see what
your saying.
Thanks for all the help.
Jim
--
http://mail.python.org/mailman/listinfo/python-list
Hi Fredrik
*sigh* I think I will stop writing mini-tutorials :)
You are, of course, correct. And I really like your method of
explaining how to mentally juggle the LC into explicit loops.
I shudder to think how mnay people I confused with my incorrect
examples - I really should have tested the
Jim <[EMAIL PROTECTED]> wrote:
> Thanks for the help. Python is somewhat mysterious to an old fortan
> programer.
You might appreciate http://www.python.org/doc/Humor.html#habits
--
http://mail.python.org/mailman/listinfo/python-list
Stephen Thorne wrote:
>> '>>> a = [i*2*b for i in range(3) for b in range(4)]
>> '>>> a
>> [0, 0, 0, 0, 0, 2, 4, 6, 0, 4, 8, 12]
>>
>> Might take you a while to correlate the answer with the loop, but you
>> should be able to see after a while that this nesting is the same as
>>
>> '>>> a = []
>>
Stephen
You're gonna have to help me here.what is the effective difference?
Thanks
Caleb
'>>> a = []
'>>> for b in range(4):
'>>> for i in range(3):
'>>> a.append(i*2*b)
There is a subtle error in this explanation. The equivilence actually
looks like:
'> a = []
'> l1 = range(4)
'> l
Jim a écrit :
Where did this type of structure come from:
mat = ['a' for i in range(3)]?
This will produce a list of three elements but
I don't see reference for it in any of the books.
Now everyone told you *what* is it, I'll (very very dumbly) answer the
question : this syntax comes from Has
On Tue, 08 Feb 2005 23:07:09 -0500, Caleb Hattingh <[EMAIL PROTECTED]> wrote:
> '>>> a = [i*2*b for i in range(3) for b in range(4)]
> '>>> a
> [0, 0, 0, 0, 0, 2, 4, 6, 0, 4, 8, 12]
>
> Might take you a while to correlate the answer with the loop, but you
> should be able to see after a while that
Jim
Someone on this list (SteveB) helped me quite a bit with a list
comprehension on a recent thread. Roy said it can be hard to read, and I
agree in part because I always thought they were hard to read, when in
actual fact I had just never bothered to learn properly. Here is a
mini-tutor
Particularly one who can't spell. Fortran.
Jim
--
http://mail.python.org/mailman/listinfo/python-list
Thanks for the help. Python is somewhat ïmysterious to an old fortan
programer.
Jim
--
http://mail.python.org/mailman/listinfo/python-list
Jim <[EMAIL PROTECTED]> wrote:
>Where did this type of structure come from:
>
>mat = ['a' for i in range(3)]?
>
>This will produce a list of three elements but
>I don't see reference for it in any of the books.
It's a list comprehension. Unfortunately, this is a bad example of
one, since a mu
On Tue, 08 Feb 2005 06:50:31 -0800 (PST), Jim <[EMAIL PROTECTED]> wrote:
> Where did this type of structure come from:
>
> mat = ['a' for i in range(3)]?
>
> This will produce a list of three elements but
> I don't see reference for it in any of the books.
It's called a "List Comprehension".
Jim,
That is called a "list comprehension", and it is a feature which
appeared in python 2.3 (iirc). Thus if your books are about earlier
versions of python, list comprehensions will not be covered.
Check out the section of the tutorial about them at
http://docs.python.org/tut/node7.html#SECTION0
Jim wrote:
> Where did this type of structure come from:
>
> mat = ['a' for i in range(3)]?
>
> This will produce a list of three elements but
> I don't see reference for it in any of the books.
Its called a list-comprehension. And as I don't know what books you mean, I
can't say if its cov
"Jim" <[EMAIL PROTECTED]> wrote:
> Where did this type of structure come from:
>
> mat = ['a' for i in range(3)]?
>
> This will produce a list of three elements but
> I don't see reference for it in any of the books.
it's called "list comprehension", and was added in Python 2.0.
http://w
Jim wrote:
Where did this type of structure come from:
mat = ['a' for i in range(3)]?
This will produce a list of three elements but
I don't see reference for it in any of the books.
It's called a list comprehension and it appeared in Python 2.0.
http://www.amk.ca/python/2.0/index.html#SECTI
Where did this type of structure come from:
mat = ['a' for i in range(3)]?
This will produce a list of three elements but
I don't see reference for it in any of the books.
--
http://mail.python.org/mailman/listinfo/python-list
26 matches
Mail list logo