Git Product home page Git Product logo

py4e-student-repo's Introduction

Dev.to LinkedIn

GitHub User's stars

Make yourself at ~

$ whoami | xargs ls:

๐ŸŒฑ Learning Go and PostGIS.

๐Ÿ‘‹ Feel free to reach out.

$ ~/skills:

Frontend

JavaScript TypeScript React Redux MobX HTML5 CSS Tailwind

Backend

Python FastAPI Node.js Express.js NestJS GraphQL Kafka MongoDB Neo4j PostgreSQL

Libraries and Tools

Docker Jest NGINX PostGIS Pytest


$ git history:

GitHub Repo Activity GitHub Repo Languages


$ exit()

py4e-student-repo's People

Contributors

kylejb avatar

Watchers

 avatar  avatar

py4e-student-repo's Issues

Explaining why ex_09_04.py commented out code has more values

https://github.com/kylejb/py4e-student-repo/blob/master/2_Python-Data-Structures/ch_09/ex_09_04.py [updated url -kylejb]

Think about what you wrote and lets walk through it

words = line.split()

First off, what is line? It's undefined at this block, but let's write the code I think you had that's breaking.

for line in handle:
  words = line.split()
  for word in words:
# Parameter to focus only on lines starting with "From "
    if line.startswith("From "):
      email = words[1]
      print(email)
    counts[email] = counts.get(email, 0) + 1

Ok, let's stub some data

line = "From [email protected] on Dec 13 2019"
words = ["From", "[email protected]", "on", "Dec", "13", "2019"]
Now you run for word in words, which is 6 iterations of your loop. That means 6 times you run this code

    if line.startswith("From "):
      email = words[1]
      print(email)
    counts[email] = counts.get(email, 0) + 1

For the exact same line. Before you even get to line 2 in the file, you've added my email 6 times because you're checking for every word. You just want to check each line in the file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.