Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week4 hienhpss #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

hienhpss
Copy link
Contributor

Week 4 solution

@@ -0,0 +1,5 @@
fname,lname,email
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. You need to submit your code only.

@@ -0,0 +1,5 @@
fname,lname,email
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. You need to submit your code only.

@@ -0,0 +1,2 @@
Bill Gates <[email protected]>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. You need to submit your code only.

print('{:s} {:s} <{:s}>'.format(str(person['fname']),str(person['lname']),str(person['email'])))

if __name__ == "__main__":
week4_output()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always have a new line at the end of your code files.

@@ -0,0 +1,56 @@
import csv
from csv import Dialect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see you using Dialect

m.update(i_enc)
return m.digest()

def week4_csv_to_dict(csv_rows):
Copy link
Member

@vietlq vietlq Oct 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't call it week4, give it some meaningful name.

if source1[key]['fname'] == source2[key]['fname'] and source1[key]['lname'] == source2[key]['lname']:
yield(source1[key])

def week4_output():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't call it week4, give it some meaningful name.

return result


def week4_match_sources():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't call it week4, give it some meaningful name.

yield(source1[key])

def week4_output():
'''Outout list of duplicate guests to file'''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error

def week4_match_sources():
'''Match the 2 input file and return the people
who subscribe to both'''
file1 = sys.argv[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather pass 2 file names to this function. Avoid accessing sys.argv to make this function reusable.

for row in csv_reader:
yield(row)

def generate_md5(*args):
Copy link
Member

@vietlq vietlq Oct 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition says each guest has only a single email, so you don't need md5, right? Have a cup of tea and think about it.

Copy link
Member

@vietlq vietlq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally it makes sense to use generators here hehe. Make some updates please ;)

for key in set(source1.keys()):
if key in set(source2.keys()):
if source1[key]['fname'] == source2[key]['fname'] and source1[key]['lname'] == source2[key]['lname']:
yield(source1[key])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats! Finally you have a valid reason to use generators ;)

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