Dipa Mehta

Dipa Mehta

  • 144
  • 12.1k
  • 470.2k

Dictionary in Python

Nov 20 2019 1:01 PM
Is there a way to refactor the following Python code so that the number of lines in generation of the dictionary can be reduced?
  1. data = frame['data'].split(';')  
  2. cat_data = {  
  3.   'xbee_address''\x00' + frame['source_addr'],  
  4.   'state': data[0],  
  5.   'flow_rate': data[1],  
  6.   'operating_hours': data[2],  
  7.   'operating_minutes': data[3],  
  8.   'operating_seconds': data[4],  
  9.   'hours_until_maintenance': data[5],  
  10.   'number_of_cleansing': data[6],  
  11.   'serial_number': data[7],  
  12.   'item_number': data[8],  
  13.   'month_of_manufacturing': data[9],  
  14.   'year_of_manufacturing': data[10],  
  15.   'software_version': data[11],  
  16. }  

Answers (2)