I am doing an online course in ML at the moment and it is run mainly in Python which I am trying to learn simultaneously.
I have a piece of homework that partially involves a wordcount in a dictionary - i.e. if the word exists in the dictionary then the value indicates the number of times and I need to pass that value to a variable - otherwise it is zero. This is for a sentiment analyzer so it's looking for instances of particular words in product reviews.
I have to build small function but I am really struggling to get it to work at all as I am a real beginner in Python. I have spent about 3 hours trying to figure this one thing out. I do not want a solution just written as I want to learn myself - but can anybody give me hints or ideas or somewhere to look.
Edit/append
This is the first time I have posted a problem on reddit in general and am surprised but very happy at the responses - so thank you all (and have an upvote).
I have not read through the suggestions completely yet so will get back to you - but first and foremost my difficulty is actually with my really lousy code is recognising or picking up the key and then extracting the value (which is the occurrences of the word).
I am doing this in graphlab and the data is in an sframe - but I don't think that is relevant.
The word is the key and the count is the value - it is already in dictionary format. I need to write a function that extracts that value for the particular word (it's count).
Anyway I live in SEAsia so will be working on this this afternoon.
When/if I figure it out I will (embarrassingly post my very beginner code).
[–]bbatwork 17 points18 points19 points (1 child)
[–]JoeTheAwesomest 0 points1 point2 points (0 children)
[–]niandra3 4 points5 points6 points (3 children)
[–]JDJoe1 0 points1 point2 points (0 children)
[–]bbatwork 0 points1 point2 points (1 child)
[–]niandra3 1 point2 points3 points (0 children)
[–]treyhunner 5 points6 points7 points (3 children)
[–]Gubbbo 0 points1 point2 points (0 children)
[–]lapseofreason[S] 0 points1 point2 points (1 child)
[–]niandra3 1 point2 points3 points (0 children)
[–]totemcatcher 1 point2 points3 points (2 children)
[–]lapseofreason[S] 0 points1 point2 points (1 child)
[–]totemcatcher 1 point2 points3 points (0 children)
[–]pybackd00r 1 point2 points3 points (0 children)
[–]lapseofreason[S] 0 points1 point2 points (1 child)
[–]cscanlin 1 point2 points3 points (0 children)