python-cs50 icon indicating copy to clipboard operation
python-cs50 copied to clipboard

I added two functions to cs50 python module.

Open OmarSSpy opened this issue 1 year ago • 2 comments

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

    The name (or path) of the CSV file to write to.

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.

OmarSSpy avatar Feb 12 '25 20:02 OmarSSpy

@rongxin-liu Can you review my pull request please or tell anyone else to check it

OmarSSpy avatar Feb 12 '25 22:02 OmarSSpy

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.

OmarSSpy avatar Feb 12 '25 22:02 OmarSSpy