The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Tuple in dict HELP!! PLEASE
Discuss Tuple in dict HELP!! PLEASE in the Python Programming forum on Dev Shed. Tuple in dict HELP!! PLEASE Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 9th, 2012, 11:29 PM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 44
Time spent in forums: 11 h 46 m 55 sec
Reputation Power: 1
|
|
|
I just need help
|

November 10th, 2012, 09:38 AM
|
 |
Contributing User
|
|
|
|
default dictionaries would be useful, though not necessary. You can learn about them here.
Given the amazing clue that you can convert an iterable to a tuple using tuple the keys of this dictionary are given by
for i in drink_list: key = tuple(i)
tuples are immutable. That means they cannot be changed. Therefor the hash function always returns the same value. That's why tuples, but not lists, can be used as dictionary keys.
You might also use the generic pattern:
container = EmptyContainer()
loop: update(container,newInformation)
__________________
[code] Code tags[/code] are essential for python code!
|

November 10th, 2012, 12:51 PM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 44
Time spent in forums: 11 h 46 m 55 sec
Reputation Power: 1
|
|
|
??
|

November 10th, 2012, 01:12 PM
|
 |
Contributing User
|
|
|
|
|
I can't think of how to say more without completely writing the function. There's not much to it.
Can you start the python interpreter? Is python installed on your computer? Find the distribution at www.python.org .
What does python respond if you type in "'hi'" ?
Can you get python to import a module? Here's an experiment to prove yourself.
Get python to show you the value of the hexdigits variable in the string module.
Am I pissing you off with these pathetic questions? Good, you're ready to go. The program you're assigned is not much harder.
|

November 10th, 2012, 01:23 PM
|
 |
Contributing User
|
|
|
|
|
PS. The doctest of your function, which you'd run on the command line with
python -m doctest -v my_python_source.py
reads
>>> build_ranking_to_frequency([['cola', 'beer', 'coffee', 'tea'], ['cola', 'beer', 'tea', 'coffee'], ['cola', 'beer', 'coffee', 'tea']])
{('cola', 'beer', 'coffee', 'tea'): 2, ('cola', 'beer', 'tea', 'coffee'): 1}
If you study dictionaries long enough and practice with them in glorious variation you'll discover---you must discover---that the output of build_ranking_to_frequency is a dictionary.
|

November 10th, 2012, 01:40 PM
|
|
Contributing User
|
|
Join Date: Oct 2012
Posts: 44
Time spent in forums: 11 h 46 m 55 sec
Reputation Power: 1
|
|
|
I am a comp major so yes i do have python visualizer and i know that i have to output a dictionary.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|