Jump to content
talkfootball365
  • Welcome to talkfootball365!

    The better place to talk football.

Python Programming


football forums

Recommended Posts

4 minutes ago, nudge said:

No, they just disappeared, ffs xD Don't know what happened there, but I just wanted to add comments to those lines:

 all_words = [] #don't forget to add the keyword into this list too, as otherwise its occurences won't be counted later

for keyword in thesaurus : #missed it earlier, but it should be 'for entry in thesaurus'

for word in entry_synonyms : keyword.append(word) #should append the all_words, not keyword!!!

xD

Here is the updated code. 

class Entry:
    def __init__(self,input_word, input_synonyms):
      self.word = input_word
      self.synonyms = input_synonyms

def search(keyword) :
  all_words = []
  for entry in thesaurus :
    if keyword == entry.word:
      for word in entry_synonyms :
        keyword.append(all_words)
     
    break
  for search_word in all_words:
    count= 0
    for document in corpus:
      for word in document:
        if search_word == word:
          count = count +1
    output: search_word, count
  

   return search(input)

input = "happy"
output = search(input)
print(output)

 

Link to comment
Share on other sites

Sign up to remove this ad.
  • Replies 160
  • Created
  • Last Reply
  • Subscriber
5 minutes ago, Eco said:

xD

Here is the updated code. 

 

Almost there, but still a few issues, check the comments in red! Hopefull my comments don't disappear this time xD 

class Entry:
    def __init__(self,input_word, input_synonyms):
      self.word = input_word
      self.synonyms = input_synonyms

def search(keyword) :
  all_words = [keyword]
  for entry in Thesaurus : 
    if keyword == entry.word:
      for word in entry_synonyms :
        keyword.append(all_words) # you should append the all_words to add the words (synonyms) from Thesaurus - so it should be all_words.append(word)
     
    break # remove this and instead create an empty list which you will then append in the second part of your function. Let's say, wordcount = []
  for search_word in all_words:
    count= 0
    for document in Corpus:
      for word in document:
        if search_word == word:
          count = count +1
    output: search_word, count 

    return search(input) #you should be returning the final list here - so in my example, return wordcount 

input = "happy"
output = search(input)
print(output)
Link to comment
Share on other sites

  • Subscriber

Shit some of it still disappears. Again:

all_words = [keyword]
keyword.append(all_words) # you should append the all_words to add the words (synonyms) from Thesaurus - so it should be all_words.append(word)
break # remove this and instead create an empty list which you will then append in the second part of your function. Let's say, wordcount = []
output: search_word, count #to get this output, append the previously created empty list. E.g. wordcount.append([search_word, count]) - so lists in a list
return search(input) #you should be returning the final list here - so in my example, return wordcount

Because the comments get screwed for some reason, here's the code:

def search(keyword) :
    all_words = [keyword]
    for entry in Thesaurus:
        if keyword == entry.word:
            for word in entry.synonyms:
                all_words.append(word)
    wordcount = []
    for search_word in all_words:
        count = 0
        for document in Corpus:
            for word in document:
                if search_word == word:
                    count = count + 1
        wordcount.append([search_word, count])
    return wordcount

This should be working...
 

Link to comment
Share on other sites

  • Subscriber
2 hours ago, Eco said:

Also, @nudge and @Mel81x - thinking about getting a book and working my way through it after this course. 

Thoughts? 

Here is the book I'm looking at. It's over 1600 pages long. 

4109Y1VgveL._SX379_BO1,204,203,200_.jpg

Looks like quite a heavy and thorough one!

I think it depends on your learning style, I personally prefer a more practical approach where I start with the syntax and basics that are easy to digest and then learn mostly by doing, looking up things I don't understand as I go. Doing the MIT Introduction to Computer Science and Programming Using Python course on edX and working through Automate the Boring Stuff gave me a decent basis to start I would say, I also like to solve challenges on Codewars, start my own small projects that I'm interested in, and read other people's code a lot - what I don't know or don't understand, I just do my research and look it up online.

 

Link to comment
Share on other sites

  • Subscriber
10 hours ago, Eco said:

Also, @nudge and @Mel81x - thinking about getting a book and working my way through it after this course. 

Thoughts? 

Here is the book I'm looking at. It's over 1600 pages long. 

4109Y1VgveL._SX379_BO1,204,203,200_.jpg

I actually have this on my shelf and its a very comprehensive book which will give you syntax and all the useful information surrounding it. Most of the O'Reilly books are great reference material for learning any programming language honestly but as @nudge alluded to, I think code is like math, reading it is great and understanding concepts but the more you do the better you get and so does your problem solving skills coupled with synatx and semantics of the language. 

Link to comment
Share on other sites

Yes, I'm still getting error messages, but I'm working to see if I can figure those out before posting here. But the code only comes up with Happy and its' synonyms, whereas we also were looking for 'Sad'. 

It is also saying that not all of the words were reporting back as accurate. 

Link to comment
Share on other sites

  • Subscriber
1 minute ago, Eco said:

Yes, I'm still getting error messages, but I'm working to see if I can figure those out before posting here. But the code only comes up with Happy and its' synonyms, whereas we also were looking for 'Sad'. 

It is also saying that not all of the words were reporting back as accurate. 

That's because your input is happy, so it looks for that word only.

Link to comment
Share on other sites

I know I'm an idiot, I get it. 

But how do I use two inputs in this code so that it checks for both the words 'happy' and 'sad' and its synonyms? 

def search(keyword) :
    all_words = [keyword]
    for entry in Thesaurus:
        if keyword == entry.word:
            for word in entry.synonyms:
                all_words.append(word)
    wordcount = []
    for search_word in all_words:
        count = 0
        for document in Corpus:
            for word in document:
                if search_word == word:
                    count = count + 1
        wordcount.append((search_word, count))
    return wordcount

input = ("happy")
output = search(input)
print(output)

 

Link to comment
Share on other sites

  • Subscriber
1 hour ago, Eco said:

I know I'm an idiot, I get it. 

But how do I use two inputs in this code so that it checks for both the words 'happy' and 'sad' and its synonyms? 


def search(keyword) :
    all_words = [keyword]
    for entry in Thesaurus:
        if keyword == entry.word:
            for word in entry.synonyms:
                all_words.append(word)
    wordcount = []
    for search_word in all_words:
        count = 0
        for document in Corpus:
            for word in document:
                if search_word == word:
                    count = count + 1
        wordcount.append((search_word, count))
    return wordcount

input = ("happy")
output = search(input)
print(output)

 

Are you sure that the input, output and print(output) aren't already in the grader and you just need to put the search function code that you wrote there? The exercise claims that your function code will be evaluated using numerous words (including happy and sad), so I'm pretty sure that is already pre-coded... 

Link to comment
Share on other sites

5 hours ago, nudge said:

Are you sure that the input, output and print(output) aren't already in the grader and you just need to put the search function code that you wrote there? The exercise claims that your function code will be evaluated using numerous words (including happy and sad), so I'm pretty sure that is already pre-coded... 

I thought so as well, but I continue to get error message so idk..

Link to comment
Share on other sites

18 minutes ago, nudge said:

Can you copy/printscreen your code and the error messages?

No need. I checked it again and found the issue. After re-submitting it it was completed. 

Woo Hoo! 

Link to comment
Share on other sites

  • Subscriber
1 minute ago, Eco said:

No need. I checked it again and found the issue. After re-submitting it it was completed. 

Woo Hoo! 

Hehe, well done! How much of the course do you still have left? What are the plans afterwards?

Link to comment
Share on other sites

Just now, nudge said:

Hehe, well done! How much of the course do you still have left? What are the plans afterwards?

I'm officially done now. 

I just bought the book I mentioned above, and will work through that, and then I want to find another course with more exercises to complete. 

Also may look into code wars and other games like that. 

Link to comment
Share on other sites

  • Subscriber
8 minutes ago, Eco said:

I'm officially done now. 

I just bought the book I mentioned above, and will work through that, and then I want to find another course with more exercises to complete. 

Also may look into code wars and other games like that. 

Nice! 

I just finished a big work project, so should now have a little bit more time to spend on python. Have a course to finish until July 15th, an am eager to start a small personal side project of my own, so will see how that goes, haha.

Link to comment
Share on other sites

13 minutes ago, nudge said:

Nice! 

I just finished a big work project, so should now have a little bit more time to spend on python. Have a course to finish until July 15th, an am eager to start a small personal side project of my own, so will see how that goes, haha.

What course are you taking? It is Python based? 

Link to comment
Share on other sites

  • Subscriber
Just now, Eco said:

What course are you taking? It is Python based? 

Currently doing the complete IBM Python Data Science program, it has 5 courses in total. The first course one in this program didn't really have much new information compared to other courses that I finished earlier so it's kind of repetitive, but I didn't want to skip it and move to the second course directly as this one introduces pandas and numpy arrays, something that I wasn't familiar with. It only took a few days anyway, and I'm now starting with the second course, which deals with analyzing data in Python (numpy, pandas, SciPy, machine learning using scikit-learn). Should take about 5 weeks, apparently. The next one then is about data visualisation in Python (5 weeks), then introduction to Machine Learning with Python (5 weeks), and then finally a practical Data Science and Machine Learning Capstone Project (6 weeks). 

I'm also already enrolled in the second course of the MIT Computational Thinking using Python XSeries program (which is my absolute favourite so far), but it doesn't start until October, so there's plenty of time to do the other ones until then...

Link to comment
Share on other sites

2 minutes ago, nudge said:

Currently doing the complete IBM Python Data Science program, it has 5 courses in total. The first course one in this program didn't really have much new information compared to other courses that I finished earlier so it's kind of repetitive, but I didn't want to skip it and move to the second course directly as this one introduces pandas and numpy arrays, something that I wasn't familiar with. It only took a few days anyway, and I'm now starting with the second course, which deals with analyzing data in Python (numpy, pandas, SciPy, machine learning using scikit-learn). Should take about 5 weeks, apparently. The next one then is about data visualisation in Python (5 weeks), then introduction to Machine Learning with Python (5 weeks), and then finally a practical Data Science and Machine Learning Capstone Project (6 weeks). 

I'm also already enrolled in the second course of the MIT Computational Thinking using Python XSeries program (which is my absolute favourite so far), but it doesn't start until October, so there's plenty of time to do the other ones until then...

This right here? 

https://www.edx.org/xseries/mitx-computational-thinking-using-python

Looks good and this is the type of class I'm wanting to take more of. 

Link to comment
Share on other sites

  • Subscriber
1 minute ago, Eco said:

This right here? 

https://www.edx.org/xseries/mitx-computational-thinking-using-python

Looks good and this is the type of class I'm wanting to take more of. 

Yes, but do the first part first: https://www.edx.org/course/introduction-to-computer-science-and-programming-7

I absolutely loved it. Very challenging and time consuming (ca. 15 hours a week), but it was my first one and I thought it was really really great. The second part comes after that, and that will start in October, that's the one I'm waiting for.

Link to comment
Share on other sites

23 minutes ago, nudge said:

Yes, but do the first part first: https://www.edx.org/course/introduction-to-computer-science-and-programming-7

I absolutely loved it. Very challenging and time consuming (ca. 15 hours a week), but it was my first one and I thought it was really really great. The second part comes after that, and that will start in October, that's the one I'm waiting for.

Nice! So I guess I can sign up tomorrow, and be done before October, and then we'll be taking the second part together. 

xD

Link to comment
Share on other sites

  • Subscriber
30 minutes ago, Eco said:

Nice! So I guess I can sign up tomorrow, and be done before October, and then we'll be taking the second part together. 

xD

Sounds good to me! :D 

Link to comment
Share on other sites

  • Subscriber
19 minutes ago, Eco said:

Did you buy the book that they recommend? 

Nope, didn't even consider buying it, haha. In fact I didn't even know there was a recommended textbook until you told me now xD Definitely didn't need it for the course...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.

Sign up or subscribe to remove this ad.


×
×
  • Create New...