| | |
Distinct Vlaues
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 46
Reputation:
Solved Threads: 11
0
#2 29 Days Ago
This sounds suspiciously like homework, so I'll just give you a hint.
someList.index(item) returns the index of the item if it's in some list. Otherwise, it'll throw ValueError.
Example:
someList.index(item) returns the index of the item if it's in some list. Otherwise, it'll throw ValueError.
Example:
Python Syntax (Toggle Plain Text)
listA = [1,2,3,5] try: listA.index(4) print "Four is in the list." except ValueError: print "Four isn't in the list."
•
•
Join Date: Dec 2006
Posts: 1,008
Reputation:
Solved Threads: 285
0
#3 29 Days Ago
This is very simple to do.
Python Syntax (Toggle Plain Text)
print len(set([1,2,4,2,7]))
Linux counter #99383
0
#4 28 Days Ago
that's really useful...
you could also do it in the old fashion way
you could also do it in the old fashion way
Python Syntax (Toggle Plain Text)
def NumDistinctDict( l ): distinct = [] for num in l: if num not in distinct: distinct += [ num ] return len( distinct )
![]() |
Other Threads in the Python Forum
- Previous Thread: Class testing
- Next Thread: ToolTip box
| Thread Tools | Search this Thread |
accessdenied advanced apache application argv array beginner book change command converter countpasswordentry csv curved dan08 def dictionary dynamic edit enter event examples file float format function google gui homework import inches input jaunty java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysqlquery newb number numbers numeric obexftp output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pygtk pyopengl python random recursion redirect remote return reverse scrolledtext session simple skinning software sprite statictext string strings syntax terminal text threading time tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable voip wordgame wxpython






