Re: [Tutor] Very basic question about lists

2008-12-23 Thread spir
> I see I have to do a loop inside a loop and that this the right expression > if word == 'ar' or word == 'ko': > > but this is not: > if word == 'ar' or 'ko': In the last example: as the 'or' operator has the least priority, it will be applied last. Which means that all other operations in the

Re: [Tutor] Very basic question about lists

2008-12-22 Thread Steve Willoughby
if 'ar' or 'ko' in item: This is incorrect. What you meant to say was: if 'ar' in item or 'ko' in item: or something equivalent to that. "if 'ar' or 'ko' in item" means "if ('ar') is True or ('ko' in item) is True". Since 'ar' is True anyway, you'll get a match every time. __

Re: [Tutor] Very basic question about lists

2008-12-22 Thread wesley chun
> list1 = ['ar', 'fir', 'wo'] > list2 = ['ber', 'gar', 'gt'] > list3 = ['hu', 'mo', 'ko', 'tr'] > list4 = ['q', 'wer', 'duh'] > > whole = [list1, list2, list3, list4] > for item in whole: >if 'ar' or 'ko' in item: >print item > > So, the unexpected result was that I got all lists printe

Re: [Tutor] Very basic question about lists

2008-12-22 Thread Eduardo Vieira
Wesley wrote: On Mon, Dec 22, 2008 at 1:19 PM, wesley chun wrote: > > in addition, i think (and i may be wrong about this) that he really > wanted to do: > > if 'arr' in list1 or 'bell' in list1... > Thanks for all the replies. Yes that was actually what I meant. My mistake too was that I gave y

Re: [Tutor] Very basic question about lists

2008-12-22 Thread spir
Le lundi 22 décembre 2008 à 11:33 -0700, Eduardo Vieira a écrit : > Hello, I'm trying to teach my self programming with python and there > are some basic things that stumps me: > Given this code: > ### > list1 = ['arr', 'bre', 'grau', 'lower', 'tudo'] > for item in list1: > if 'arr' in item: >

Re: [Tutor] Very basic question about lists

2008-12-22 Thread wesley chun
>> if 'arr' or 'bell' in item: > > The interpreter sees this as > if ('arr') or ('bell' in item): > > 'arr' always evaluates to True so the condition is always true. The > correct way to express this condition is > if 'arr' in item or 'bell' in item: arrgh. yes, i saw this too but forgot to ment

Re: [Tutor] Very basic question about lists

2008-12-22 Thread Kent Johnson
On Mon, Dec 22, 2008 at 1:33 PM, Eduardo Vieira wrote: > if 'arr' or 'bell' in item: The interpreter sees this as if ('arr') or ('bell' in item): 'arr' always evaluates to True so the condition is always true. The correct way to express this condition is if 'arr' in item or 'bell' in item:

Re: [Tutor] Very basic question about lists

2008-12-22 Thread wesley chun
eduardo, welcome to programming, and even better, welcome to Python! you've done your research and found a list of great people who can help you out. with regards to your question, my comment are below... > list1 = ['arr', 'bre', 'grau', 'lower', 'tudo'] > for item in list1: >if 'arr' in it

Re: [Tutor] Very basic question about lists

2008-12-22 Thread Robert Berman
#! /usr/bin/python list1 = ['arr', 'bre', 'grau', 'lower', 'tudo'] for item in list1: if item == 'arr' or item == 'grau':     print list1 Hopefully, my rewording of one of your tests will make it a bit easier to see what is happening. A for statement such as 'for item in list

[Tutor] Very basic question about lists

2008-12-22 Thread Eduardo Vieira
Hello, I'm trying to teach my self programming with python and there are some basic things that stumps me: Given this code: ### list1 = ['arr', 'bre', 'grau', 'lower', 'tudo'] for item in list1: if 'arr' in item: print list1 ### The output is (as expected): ['arr', 'bre', 'grau', 'lower