Larry Bates wrote:
> First things first: > > Don't name a variable "dict" because if you do it shadows > the built in dict function (same goes for list, str, ...). > This WILL bite you later, so start now by not naming > variables by any built in names. -- Thanks, got it! > > Now to your question: > > for x in <something>: requires <something> be an iterable > (e.g. list, tuple, iterable class instance, etc) so there > is something that it can loop over one object at at time. > > >>for x in [ x in dict if dict[x]=="thing" ]: > > > needs to be written (if I'm understanding what you are > doing) as: > > for x in [x for x in d if d[x]=="thing"]: -- Ywes, I understand the syntax, but think it is repetitive and cumbersome. Just note the "for x in x for x in ..." no new semantics of the desired iteration set given, all redundant syntax. I still wonder why one cannot qualify a for list iteration object with an list_if Greg >>For example; >>Instead of; >> for x in [ x in dict if dict[x]=="thing" ]: >>in this: >> for x in dict and dict[x]=="thing": >>x is undefined. >> >>And why doesn't this work: >> for x in dict if dict[x]=="thing": >> >>Any insights/hints on why it is broken? >> >>Thanks, >>Gregory >>---------------------------------------- >>http://docs.python.org/ref/grammar.txt: >>list_for ::= >> "for" expression_list "in" testlist >> [list_iter] >>testlist ::= >> test ( "," test )* [ "," ] >>list_iter ::= >> list_for | list_if >>list_if ::= >> "if" test [list_iter] >> >> >>----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet >>News==---- >>http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ >>Newsgroups >>----= East and West-Coast Server Farms - Total Privacy via Encryption =---- ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =---- -- http://mail.python.org/mailman/listinfo/python-list