I added two functions to cs50 python module.#188
Open
Conversation
…ds 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.
OmarSSpy
commented
Feb 12, 2025
Author
OmarSSpy
left a comment
There was a problem hiding this comment.
I created two more functions for the user to use. One reads a csv and returns the values read. The other function implements binary search as a function that returns the index of the target in the list given
Author
|
@rongxin-liu |
Author
|
Thanks rongxin-liu for asking professor malan :) By the way @dmalan , if you need me to change anything feel free to tell me and I just wanted to say you are an incredible teacher. I love how you teach computer science because I am currently taking CS50x and its AWESOME. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.