Exercise: Refactoring - Extract CSV Reading Into Function (csv.dictreader)

Requirement

Following Exercise: Read CSV File (csv.dictreader), refactor read-userdb-header.py to not directly output the user records as specified.

Rather, create a function that reads the CSV file, and returns a list of user records - dictionaries with specified keys - of the form,

{
    'id': 2,    # int
    'firstname': 'Jörg',
    'lastname': 'Faschingbauer',
    'birth': '19.6.1966',
}

That list is then used as follows in the main part of the program (the part that creates the output which remains the same):

user_records = read_csv_header(filename)
for rec in user_records:
    ... create output like before, no change ...

Dependencies

cluster_python Python Programming: From Absolute Beginner to Advanced Productivity cluster_python_basics Python: The Language Fundamentals cluster_python_exercises Exercises cluster_python_exercises_userdb User Database (Exercise Series) cluster_python_misc Python: Miscellaneous Topics python_basics_python_0300_strings More About Strings python_basics_python_0150_datatypes_overview Datatypes python_basics_python_0300_strings->python_basics_python_0150_datatypes_overview python_basics_python_0200_sequential_types Sequential Datatypes python_basics_python_0300_strings->python_basics_python_0200_sequential_types python_basics_python_0250_refs_flat_deep_copy References, (Im)mutability python_basics_python_0300_strings->python_basics_python_0250_refs_flat_deep_copy python_basics_python_0130_syntax_etc Syntax etc. python_basics_python_0120_helloworld Hello World python_basics_python_0130_syntax_etc->python_basics_python_0120_helloworld python_basics_python_0110_blahblah Blahblah python_basics_python_0120_helloworld->python_basics_python_0110_blahblah python_basics_python_0220_for for Loops python_basics_python_0193_while while Loops python_basics_python_0220_for->python_basics_python_0193_while python_basics_python_0220_for->python_basics_python_0200_sequential_types python_basics_python_0139_commandline_argv Commandline Arguments (sys.argv) python_basics_python_0139_commandline_argv->python_basics_python_0130_syntax_etc python_basics_python_0125_running Running Python Programs python_basics_python_0139_commandline_argv->python_basics_python_0125_running python_basics_python_0140_variables Variables python_basics_python_0140_variables->python_basics_python_0130_syntax_etc python_basics_python_0150_datatypes_overview_compound Compound Datatypes python_basics_python_0150_datatypes_overview_compound->python_basics_python_0150_datatypes_overview python_basics_python_0160_boolean Boolean python_basics_python_0160_boolean->python_basics_python_0150_datatypes_overview python_basics_python_0193_while->python_basics_python_0160_boolean python_basics_python_0170_if The if Statement python_basics_python_0193_while->python_basics_python_0170_if python_basics_python_0170_if->python_basics_python_0160_boolean python_basics_python_0150_datatypes_overview->python_basics_python_0140_variables python_basics_python_0270_functions Functions python_basics_python_0270_functions->python_basics_python_0140_variables python_basics_python_0270_functions->python_basics_python_0150_datatypes_overview python_basics_python_0125_running->python_basics_python_0120_helloworld python_basics_python_0200_sequential_types->python_basics_python_0150_datatypes_overview_compound python_basics_python_0330_strings_encoding Strings and Encoding python_basics_python_0330_strings_encoding->python_basics_python_0300_strings python_basics_python_0250_refs_flat_deep_copy->python_basics_python_0140_variables python_basics_python_0250_refs_flat_deep_copy->python_basics_python_0150_datatypes_overview_compound python_basics_python_0250_refs_flat_deep_copy->python_basics_python_0150_datatypes_overview python_basics_python_0500_files File I/O python_basics_python_0500_files->python_basics_python_0220_for python_basics_python_0500_files->python_basics_python_0330_strings_encoding python_exercises_userdb_csvdictreader_function Exercise: Refactoring - Extract CSV Reading Into Function (csv.dictreader) python_exercises_userdb_csvdictreader_function->python_basics_python_0270_functions python_exercises_userdb_csvdictreader Exercise: Read CSV File (csv.dictreader) python_exercises_userdb_csvdictreader_function->python_exercises_userdb_csvdictreader python_exercises_userdb_csvdictreader->python_basics_python_0139_commandline_argv python_exercises_userdb_csvreader Exercise: Read CSV File (csv.reader) python_exercises_userdb_csvdictreader->python_exercises_userdb_csvreader python_misc_csv CSV Files python_exercises_userdb_csvdictreader->python_misc_csv python_exercises_userdb_csvreader->python_basics_python_0139_commandline_argv python_exercises_userdb_csvreader->python_misc_csv python_misc_csv->python_basics_python_0220_for python_misc_csv->python_basics_python_0150_datatypes_overview_compound python_misc_csv->python_basics_python_0500_files