Example
Returning Dictionary or List
Functions can return complex data structures like dictionaries or lists.
Showing 21–30 of 58
Example
Functions can return complex data structures like dictionaries or lists.
Quiz
…and **kwargs: 15 questions on extra arguments, tuples, dictionaries, and * and ** in calls. Instant answers.
Challenge
Turn the day's mission summary dict into JSON text with json.dumps() and indent=2, see what True, False and None become, then keep the station's Polish letters readable and sort the keys so the files…
Quiz
…15 questions on return, None, several values, lists, dictionaries and early exit. Instant answers.
Challenge
…to record" into parse_line(line), which returns the record dict, then let it return None for blank, comment and damaged lines so the loop only keeps real records.
Challenge
…that maps planets and the Moon to surface gravity with a dict and one get() lookup, keeping the output exactly the same, then loop over the dict for a weight table.
Challenge
…flag, save. Validate the rows Read telemetry.csv with csv.DictReader . Reject a row whose sensor is not in LIMITS , or whose value is not a number, with its line number in the file: the header is line…
Challenge
…True alerts: all DEFAULTS.copy() makes a separate dict, and settings.update(user_settings) overwrites the keys the user set. Unknown settings A user's profile has a typo: "dark_mod" . With update() it…
Challenge
…= "DEBUG" retries = 12 safe_mode = "yes" timeout_s = 2.5 dict(DEFAULTS) makes the copy and update() fills it in. json.dumps(value) shows the difference between "256" and 256 . Every problem at once…
Challenge
…line, then save the same data as a CSV file with csv.DictWriter for the spreadsheet people.