I added two functions to cs50 python module. #188
+63
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New functions for cs50
Based on my experience with python during cs50x week 6, I didnt understand much of how .csv files worked and how to read them but eventually I did understand how to read those files. So with these functions I think we can make learning easier in cs50x to less comfortable audiences.
Syntax
The first function reads a .csv file and handles some errors. The other function implements binary search, where you pass an array and the target you are looking for, this function returns the index of the target in the given array if successful.
read_csv function
y = read_csv(file:str)
binary_search function
x = binary_search(array, target)
###write_csv function
Writes a list of lists to a .csv file,
file : str
data : list
A list of lists, where each inner list represents a row in the CSV file.
data = [["Name", "Age"], ["Alice", 25], ["Bob", 30]]
write_csv("people.csv", data)
This function returns True if successfull or False if an error occurred.
I believe this changes will make easier lo learn python during the cs50x course,
Thank you.