[Tutor] Compound if statement question.

2011-05-01 Thread Greg Christian
Is there a way to write an if statement that will pick up duplicates (two ‘1’s): L = ['1', '4', '1'] if (L[0]) != (L[1]) != (L[2]): print "THEY ARE NOT EQUAL" else: print "THEY ARE EQUAL" When I run this code, it prints “THEY ARE NOT EQUAL” when it should print the else “THEY ARE EQUAL”.

[Tutor] Reading elements in a file

2011-05-04 Thread Greg Christian
I am kind of stuck on what is probably a simple thing: If we have a file of words like this: “first”,”word”,”in”,”that”,”another”,”part”,”of”,”this” f = open('words.txt', "r") words = f.read() will read the whole file, is there a way to read just the words: first word in that another part

[Tutor] Reading elements in a file

2011-05-04 Thread Greg Christian
Python version = 2.7.1 Platform = win32 I am kind of stuck on what is probably a simple thing: If we have a file of words like this: “first”,”word”,”in”,”that”,”another”,”part”,”of”,”this” f = open('words.txt', "r") words = f.read() will read the whole file, is there a way to read just the

[Tutor] How is the return statement working in this function?

2012-04-05 Thread Greg Christian
I am just wondering if anyone can explain how the return statement in this function is working (the code is from activestate.com)? Where does x come from – it is not initialized anywhere else and then just appears in the return statement. Any help would be appreciated. def primes(n): """Pr

[Tutor] TypeError: 'int' object is not callable

2012-05-16 Thread Greg Christian
Can anyone tell me what I am doing wrong here. When trying to call the factors function from main with x = factors(Tn), getting the error message: “TypeError: 'int' object is not callable”? Any help would be appreciated. Thanks. def factors(n): L = [] for i in range(1, int(n ** 0.5) + 1

[Tutor] Using sorted in Python 3.3.5

2015-11-19 Thread Greg Christian
I’m trying to sort a list of tuples based on the second item in the tuple. When I run this in IDLE I get the correct output; however, when running inside of a program, and calling the counter() function, sorted does not seem to work? Any ideas on why this works in IDLE and not in program would b