Could someone please go through this code line by line and explain it in Pseudocode or English

Some info on enumerate by typing help(enumerate) enumerate(iterable[, start]) -> iterator for index, value of iterable Return an enumerate object. iterable must be another object that supports iteration. The enumerate object yields pairs containing a count (from start, which defaults to zero) and a value yielded by the iterable argument. enumerate is useful for obtaining … Read more

How to open a file within python?

This is the reason a try/catch block is often ill-advised. Your error was not that the file could not be opened, but instead that this line was throwing an error: f.write(student + “\n”) + does not append a dictionary (student) and a string (\n). Your try/catch block is reporting this as an open file error.

Finding and counting the frequency of known pairs of words in multiple files [closed]

When using combinations() you are getting all pairs, even the non-adjacent ones. You can create a function that will return the adjacent pairs. I’ve tried the following code and it worked, maybe it can give you some insight: import os import re from collections import Counter def pairs(text): ans = re.findall(r'[A-Za-z]+’, text) return (tuple(ans[i:i+2]) for … Read more

Oops, try again. Your function failed on the message yes. It returned 'yes' when it should have returned 'Shutting down'

Couple of points: Misplaced return statement. Should be at end. if yes(): It is wrong. You want to compare function input with yes. It should be if s == ‘yes’:. Same for rest also. Since you have written function definition as def shut_down(s):, it is expecting one argument. You should pass one argument while calling … Read more