One thing to note: I wrote:
year = [0] * 1000
Here's another way to get something equivalent:
year = []
for i in range(1000):
year.append(0)
Here, we do an explicit loop to append those thousand zeros into the
list. We'll end up with the same situation as before: year i
If we wanted to do something with something like:
year0 = 0
year1 = 0
year2 = 0
...
year999 = 0
where we keep a thousand years, and set them all to zero, then you're
right in thinking that having one thousand separate variables is
probably not a viable approach.
We can handl
On Sat, Jan 18, 2014 at 6:24 PM, Keith Winston wrote:
>
> I guess it makes sense that iter() returns a type iterator.
`iter(obj)` returns `obj.__iter__()` if the method exists and the
result is an iterator, i.e. has a `__next__` method.
Otherwise if `obj.__getitem__` exists, it returns a generic
On 18/01/14 22:52, Jackie Canales wrote:
def processScores(filename):
infile = open(filename, 'r')
line = infile.readlines()
infile.close()
lineNum = 0
s = Score(0)
for item in line2:
> lineNum += 1
What is line2? I assume you mean line?
You could do al
On 13-12-31 04:09 PM, Keith Winston wrote:
> Hi PierreD, I think if you iterate over your strings with something like
> this, it will do what you want, if I understand correctly (snum is your
> string number, like "123,321"):
>
> fnum = float(snum.replace(",", ".")
>
> keith: rank beginner, tak
Hello,
I wish to fill a list called years[] with a hundred lists called
year1900[], year1901[], year1902[], ..., year1999[]. That is too much
typing of course. Any way of doing this in a loop? I've tried stuff like
("year" + str(1900)) = [0,0] but nothing works.
Any solution?
Thank you,
PierreD.
I have with my assignment.
class Score:
'A subclass of the object.'
def __init__(self, init):
'Sets the initial score to the object and sets the number of scores
that have contributed to the total to 1.'
self.x = 1
self.init = int(init)
self.total = i
On Sat, Jan 18, 2014 at 2:19 PM, eryksun wrote:
> `xrange` and 3.x `range` aren't iterators. They're sequences. A
> sequence implements `__len__` and `__getitem__`, which can be used to
> implement an iterator, reversed iterator, and the `in` operator (i.e.
> `__contains__`).
I'm so glad you said
On Sat, Jan 18, 2014 at 4:22 AM, Chris “Kwpolska” Warrick
wrote:
> Here is a poor man’s pure-python re-implementation of `for`:
> https://gist.github.com/Kwpolska/8488091
This will be very handy the next time I run out of for's, or have a
surplus of while's. Fairly common.
Seriously though, than
On Sat, Jan 18, 2014 at 4:22 AM, Chris “Kwpolska” Warrick
wrote:
> For Python 2, use xrange() instead to get an iterator. In Python 3,
> range() is already an iterator.
`xrange` and 3.x `range` aren't iterators. They're sequences. A
sequence implements `__len__` and `__getitem__`, which can be u
On Sat, Jan 18, 2014 at 12:51 PM, Reuben wrote:
>
> I tried reading information regarding decorators - but not able to get a
> good grip around it.
>
> Kindly point me to some good links along with examples
Decorators I: Introduction to Python Decorators
http://www.artima.com/weblogs/viewpost.jsp
On Sat, Jan 18, 2014 at 4:50 AM, Peter Otten <__pete...@web.de> wrote:
>
> PS: There is an odd difference in the behaviour of list-comps and generator
> expressions. The latter swallow Stopiterations which is why the above
> myzip() needs the len() test:
A comprehension is building a list in a `fo
Hi,
I tried reading information regarding decorators - but not able to get a
good grip around it.
Kindly point me to some good links along with examples
Regards,
Reuben
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription optio
erratum:
On 01/18/2014 12:13 PM, spir wrote:
[Note, just to compare: in Lua, this little magic making builtin sequences
special does not exist. So, to iterate over all items or pairs of a Lua table,
one would write explicitely, resp.:
for key,val in pairs(t)
for item in ipairs(t)
where
On 01/18/2014 09:51 AM, Keith Winston wrote:
I don't really get iterators. I saw an interesting example on
Stackoverflow, something like
with open('workfile', 'r') as f:
for a, b, c in zip(f, f, f):
And this iterated through a, b, c assigned to 3 consecutive lines of
the file as it it
Keith Winston wrote:
> I don't really get iterators. I saw an interesting example on
> Stackoverflow, something like
>
> with open('workfile', 'r') as f:
> for a, b, c in zip(f, f, f):
>
>
> And this iterated through a, b, c assigned to 3 consecutive lines of
> the file as it iterates t
On Sat, Jan 18, 2014 at 9:51 AM, Keith Winston wrote:
> I don't really get iterators. I saw an interesting example on
> Stackoverflow, something like
>
> with open('workfile', 'r') as f:
> for a, b, c in zip(f, f, f):
>
>
> And this iterated through a, b, c assigned to 3 consecutive lines
I don't really get iterators. I saw an interesting example on
Stackoverflow, something like
with open('workfile', 'r') as f:
for a, b, c in zip(f, f, f):
And this iterated through a, b, c assigned to 3 consecutive lines of
the file as it iterates through the file. I can sort of pretend t
18 matches
Mail list logo