-3

I'm looking to implement the pLSI algorithm in R. I found this python code, but I am stuck in a few places, like line #8 for termID, value in docTermDic[docID].iteritems():. In this case I don't understand how to implement both termID & value inside a for loop, and what docTermDic[docID].iteritems() is.

Is there any tool available using which I can extract the algo or the pseudocode so as to enable me to code it up myself?

jackStinger
  • 2,035
  • 5
  • 23
  • 36
  • 6
    Sorry, you're gonna have to learn the language. – Zirak Dec 31 '12 at 07:39
  • "In this case I don't understand how to implement both termID & value inside a for loop, and what docTermDic[docID].iteritems() is." Documentation and Google are very useful in such scenarios. – Waleed Khan Dec 31 '12 at 08:31

2 Answers2

0

Related answers:

What is the difference between dict.items() and dict.iteritems()?

Why do you have to call .iteritems() when iterating over a dictionary in python?

A simple Google search tells you that iteritems() gives you an iterator for a dict:check this

Community
  • 1
  • 1
  • Unless you actually explain something in this answer, this will probably be downvoted as link-only answers are not acceptable in StackOverflow – asheeshr Dec 31 '12 at 07:48
  • 2
    The answers are good enough for such a poor question where the OP is obviously unmotivated for doing basic research himself. Better downvote the OP instead of downvoting the messenger bringing the bad news. –  Dec 31 '12 at 08:19
  • I did not downvote, but if this shows up in Reviews, it most certainly will be downvoted. – asheeshr Dec 31 '12 at 08:22
  • @CRUSADER I am sorry that I disappointed you. I promise to be more motivated from hereon. Hope this makes you feel better. And thank you for the links. They were helpful, more the knowledge, the better, you know! – jackStinger Jan 03 '13 at 07:33
0

Is there any tool available using which I can extract the algo or the pseudocode so as to enable me to code it up myself?

Well, python is designed to look like some kind of pseudocode. It looks like what you're asking is something that will scan your brain in order to find what you don't understand and explain it you. I suppose it doesn't exist.

For the specific part of the question about dictionaries :

for termID, value in docTermDic[docID].iteritems() :

this will iterate through all pairs (key,value) in the dict, and affect both key and value. You can't do it in every language. If your language can't do this, just do something like :

for termID in docTermDic[docID].keys() :
    value = docTermDic[docID][termID]

iterate through all keys, and affect the value as first instruction.

Paul Etherton
  • 391
  • 3
  • 11
giss
  • 26
  • 2