| | |
Distinct Vlaues
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 45
Reputation:
Solved Threads: 10
0
#2 28 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 28 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 27 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 |
abrupt alarm ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui halp heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib






