May-02-2018, 11:42 PM
(May-02-2018, 08:15 AM)toxicxarrow Wrote: Any suggestions on how to make it more neat, so that the index of each array gets paired up in a column?A dictionary is a natural solution for this.
λ ptpython >>> months = ['January', 'Febuary', 'March', 'April', 'May', 'June', ... 'July', 'August', 'September', 'October', 'November', 'December'] ... rain = [40, 45, 30, 20, 15, 12, 13, 10, 17, 19, 20, 35] >>> record = dict(zip(months, rain)) >>> record {'January': 40, 'Febuary': 45, 'March': 30, 'April': 20, 'May': 15, 'June': 12, 'July': 13, 'August': 10, 'September': 17, 'October': 19, 'November': 20, 'December': 35} >>> # Then look up is easy >>> record['March'] 30 >>> record.get('May', 'Not in record') 15 >>> record.get('holliday', 'Not in record') 'Not in record'