Skip to content

Make examples in '02_Containers.md' executable#45

Merged
dabeaz merged 1 commit into
dabeaz-course:masterfrom
echasnovski:02-containers-fix
Jun 6, 2020
Merged

Make examples in '02_Containers.md' executable#45
dabeaz merged 1 commit into
dabeaz-course:masterfrom
echasnovski:02-containers-fix

Conversation

@echasnovski
Copy link
Copy Markdown
Contributor

This PR makes example of list construction when reading from a file executable.

There is also an issue with "Dict Construction" from file example. It gives an error because 'Data/prices.csv' file has an empty last row. I'd make a change to account for that but not sure if this clutters example clarity too much:

prices = {} # Initial empty dict

with open('Data/prices.csv', 'rt') as f:
    for line in f:
        row = line.split(',')
        if len(row) >= 2: # Ensure enough data in a row
            prices[row[0]] = float(row[1])

If this change is desirable, I'll update this PR.

@dabeaz
Copy link
Copy Markdown
Contributor

dabeaz commented Jun 6, 2020

I added a note about the blank line, but did not provide a solution. This is something that needs to be solved in Exercise 2.6.

@dabeaz dabeaz closed this Jun 6, 2020
@echasnovski
Copy link
Copy Markdown
Contributor Author

Hello, @dabeaz.
This PR isn't about blank line in 'Data/prices.csv'.
It is mostly about syntax error in example (here one of closing parenthesis is misplaced). I also added skipping header of 'Data/portfolio.csv', because it has already been showed as a workaround. If it is not needed, I'll remove it.

@dabeaz
Copy link
Copy Markdown
Contributor

dabeaz commented Jun 6, 2020

Apologies. Misread it.

@dabeaz dabeaz reopened this Jun 6, 2020
@dabeaz dabeaz merged commit d47e806 into dabeaz-course:master Jun 6, 2020
@echasnovski echasnovski deleted the 02-containers-fix branch June 12, 2020 12:58
bytemux pushed a commit to bytemux/practical-python that referenced this pull request Nov 3, 2020
Make examples in '02_Containers.md' executable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants