Re: Last iteration?
On Oct 12, 11:58 am, Florian Lindner <[EMAIL PROTECTED]> wrote: > Hello, > can I determine somehow if the iteration on a list of values is the last > iteration? > > Example: > > for i in [1, 2, 3]: >if last_iteration: > print i*i >else: > print i > > that would print > > 1 > 2 > 9 > > Can this be acomplished somehow? > Another suggestion: l = [1, 2, 3] for i in l[:-1]: print i i = l[-1] print i*i James -- http://mail.python.org/mailman/listinfo/python-list
Re: python newbie
On Nov 2, 3:35 pm, Jim Hendricks <[EMAIL PROTECTED]> wrote: > > This sounds like an issue of terminology. I understand that I don't > declare variables like I would in C or Java, but that they are > implicitly declared via the first assignment. And the define objects > and bind a name to them makes no sense to me. I can only assume that if > I say: my_file = open( ... the "techy" explaination is that the open > function defines a file object and binds the name my_file to it. To me, > it's easier to say that the open function creates a file object and > assigns a reference to the my_file variable. If my_file does not exist, > it is created, if my_file does exist, prior to the assignment, the type > of my_file is checked to ensure type safety. > Objects have types, names (what you're calling variables) don't. my_file = open ... binds the name 'my_file' to a file object. A subsequent my_file = 7 will bind the name 'my_file' to an int object. No type-checking involved (but neither is there any loss of type safety). James -- http://mail.python.org/mailman/listinfo/python-list
List comp bug?
I seem to have stumbled across a problem with list comprehensions (or perhaps it's a misunderstanding on my part) [f() for f in [lambda: t for t in ((1, 2), (3, 4))]] is giving me [(3, 4), (3, 4)] The equivalent using a generator expression: [f() for f in (lambda: t for t in ((1, 2), (3, 4)))] is giving me [(1, 2), (3, 4)] as expected. Is this a known bug? I'm using Python 2.4.3 Thanks James -- http://mail.python.org/mailman/listinfo/python-list