sdobbers
May 15th, 2008, 06:22 PM
Hey guys,
I'm pretty new to programming in Python (and well programming in general...did it a few years back, but just getting back into it). I have a question about this program I'm working on, and was hoping you guys might be able to give me a nudge in the right direction.
A little background on the program. I'm creating a code library, so that when I find bits of code online I can put them into a file of mine. I add a title, some title keywords (...redundant, but at the time for some reason it didn't cross my mind to just search the title directly...), and some keywords that tell us what the program does. Then I have a little menu that asks whether you want to search by title, or keyword. Once you preform the search, it spits out a list of Titles that matched...then you type in the number and out pops the code snippet.
Ideally, what I'd like to do is sort it by the one that got the most 'hits'. Right now it's just in a random order...which isn't a problem at the moment considering I only have a total of 9 unrelated code snippets. However, once my library grows it will become a problem.
Now what I've thought about doing is, counting the number of hits in the "found list" and assigning it to a dictionary of {title:# of hits}. From here, is there any way to sort by value instead of key? If not, is there a more efficient way to go about this?
Thanks in advance,
Sean
I'm pretty new to programming in Python (and well programming in general...did it a few years back, but just getting back into it). I have a question about this program I'm working on, and was hoping you guys might be able to give me a nudge in the right direction.
A little background on the program. I'm creating a code library, so that when I find bits of code online I can put them into a file of mine. I add a title, some title keywords (...redundant, but at the time for some reason it didn't cross my mind to just search the title directly...), and some keywords that tell us what the program does. Then I have a little menu that asks whether you want to search by title, or keyword. Once you preform the search, it spits out a list of Titles that matched...then you type in the number and out pops the code snippet.
Ideally, what I'd like to do is sort it by the one that got the most 'hits'. Right now it's just in a random order...which isn't a problem at the moment considering I only have a total of 9 unrelated code snippets. However, once my library grows it will become a problem.
Now what I've thought about doing is, counting the number of hits in the "found list" and assigning it to a dictionary of {title:# of hits}. From here, is there any way to sort by value instead of key? If not, is there a more efficient way to go about this?
Thanks in advance,
Sean