Python File IO Basics #25 Non volitile: which does not gets vanish when laptop is turned off . volitile: which does gets vanish when laptop is turned off . r : r mode opens a file for read.-default w : w mode opens a file for read. x : x creates a new file. It does not work for an already existing file, as in such cases the operation fails. a : a for append, which means to add something to the end of the file. It just adds the data we like in write(w) mode but instead of overwriting it just adds it to the end of the file t : used to open our file in text mode. It deals with the file data as a string.-default b : b for binary and this mode can only open the binary files, that are read in bytes. The binary files include images, documents, or all other files that require specific software to be read. + :we can read and write a file simultaneously. The mode is mostly used in cases where we want to update our file. #26 Open(), Read(), Readline() #To read: ...
''' You are given few sentences as a list (Python list of sentences). Take a query string as an input from the user. You have to pull out the sentences matching this query inputted by the user in decreasing order of relevance after converting every word in the query and the sentence to lowercase. Most relevant sentence is the one with the maximum number of matching words with the query. Sentences = [“This is good”, “python is good”, “python is not python snake”] Input: Please input your query string “Python is” Output: 3 results found: 1. python is not python snake 2. python is good 3. This is good ''' def mathingWords(sentence1, sentence2): words1 = sentence1.strip().split(" ") words2 = sentence2.strip().split(" ") score = 0 for word1 in words1: for word2 in words2: # print(f"Matching {word1} with {word2}") i...
Comments
Post a Comment