{"action":"created","issue":{"url":"https://api.github.com/repos/joelgrus/data-science-from-scratch/issues/58","repository_url":"https://api.github.com/repos/joelgrus/data-science-from-scratch","labels_url":"https://api.github.com/repos/joelgrus/data-science-from-scratch/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/joelgrus/data-science-from-scratch/issues/58/comments","events_url":"https://api.github.com/repos/joelgrus/data-science-from-scratch/issues/58/events","html_url":"https://github.com/joelgrus/data-science-from-scratch/issues/58","id":369797398,"node_id":"MDU6SXNzdWUzNjk3OTczOTg=","number":58,"title":"Crashcourse to Python - defaultdict","user":{"login":"felix4webscience","id":22968539,"node_id":"MDQ6VXNlcjIyOTY4NTM5","avatar_url":"https://avatars3.githubusercontent.com/u/22968539?v=4","gravatar_id":"","url":"https://api.github.com/users/felix4webscience","html_url":"https://github.com/felix4webscience","followers_url":"https://api.github.com/users/felix4webscience/followers","following_url":"https://api.github.com/users/felix4webscience/following{/other_user}","gists_url":"https://api.github.com/users/felix4webscience/gists{/gist_id}","starred_url":"https://api.github.com/users/felix4webscience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felix4webscience/subscriptions","organizations_url":"https://api.github.com/users/felix4webscience/orgs","repos_url":"https://api.github.com/users/felix4webscience/repos","events_url":"https://api.github.com/users/felix4webscience/events{/privacy}","received_events_url":"https://api.github.com/users/felix4webscience/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-13T12:22:45Z","updated_at":"2018-11-29T04:59:52Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI got a problem in Chapter 2 (German version) with example about \"Defaultdict\" and also \"Counter\".  \r\n\r\nWhats seems to be left out here is, how the value \"document\" has been defined. \r\n\r\n**Code:**\r\n_```\r\nfrom collections import defaultdict\r\nword_counts = {}\r\nfor word in document:\r\n    if word in word_counts:\r\n        word_counts[word] += 1\r\n    else:\r\n        word_count[word] = 1\r\n```_\r\n\r\nI always get an error message like this: \r\n\"name 'document' is not defined\"\r\n\r\nas a matter of this error the following code examples are all not working as well:\r\n- Counter - because word_counts can not work without the code before\r\n- Sets - same here...\r\n\r\nFor subsection  Bolean, the code does not work neither:\r\n\r\ns = some_function_that_returns_a_string()\r\nif s:\r\n    first_char = s[0]\r\nelse:\r\n    first_char = \"\"\r\n\r\nthe following error appears:\r\nNameError: name 'some_function_that_returns_a_string' is not defined\r\n\r\nand the same holds for:\r\nfirst_char = s and s[0]\r\n\r\nAny help or hint, would be great.\r\n"},"comment":{"url":"https://api.github.com/repos/joelgrus/data-science-from-scratch/issues/comments/442706974","html_url":"https://github.com/joelgrus/data-science-from-scratch/issues/58#issuecomment-442706974","issue_url":"https://api.github.com/repos/joelgrus/data-science-from-scratch/issues/58","id":442706974,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MjcwNjk3NA==","user":{"login":"devAmoghS","id":16324607,"node_id":"MDQ6VXNlcjE2MzI0NjA3","avatar_url":"https://avatars1.githubusercontent.com/u/16324607?v=4","gravatar_id":"","url":"https://api.github.com/users/devAmoghS","html_url":"https://github.com/devAmoghS","followers_url":"https://api.github.com/users/devAmoghS/followers","following_url":"https://api.github.com/users/devAmoghS/following{/other_user}","gists_url":"https://api.github.com/users/devAmoghS/gists{/gist_id}","starred_url":"https://api.github.com/users/devAmoghS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/devAmoghS/subscriptions","organizations_url":"https://api.github.com/users/devAmoghS/orgs","repos_url":"https://api.github.com/users/devAmoghS/repos","events_url":"https://api.github.com/users/devAmoghS/events{/privacy}","received_events_url":"https://api.github.com/users/devAmoghS/received_events","type":"User","site_admin":false},"created_at":"2018-11-29T04:59:52Z","updated_at":"2018-11-29T04:59:52Z","author_association":"NONE","body":"@felix4webscience \r\ndocument is a variable that is user-defined actually.\r\n\r\nThis might help to understand it better\r\n\r\n```\r\ndef get_document():\r\n    url = \"http://radar.oreilly.com/2010/06/what-is-data-science.html\"\r\n    html = requests.get(url).text\r\n    soup = BeautifulSoup(html, 'html5lib')\r\n\r\n    content = soup.find(\"div\", \"article-body\")  # find article-body div\r\n    regex = r\"[\\w']+|[\\.]\"  # matches a word or a period\r\n\r\n    document = []\r\n\r\n    for paragraph in content(\"p\"):\r\n        words = re.findall(regex, fix_unicode(paragraph.text))\r\n        document.extend(words)\r\n\r\n    return document\r\n```\r\nUse it like this\r\n`document = get_document()`\r\n\r\nThen run your code on the document variable.\r\n\r\nHope this helps."}}
{"actor":{"display_login":"devAmoghS"}}