This is a clear use case for classes.
Instead of having lists that represent companies like ['jhon', 'abc', 'wa@gmail.com']
, python gives you the possibility to model that as a class:
class Company:
def __init__(self, manager_name, owner_name, email):
self.manager_name = manager_name
self.owner_name = owner_name
self.email = email
companies = {10: Company('jhon', 'abc', 'wa@gmail.com'),
12: Company('raghav', 'awdaw', 'raghavpatnecha15@gmail.com'}
This gives you a much nicer interface than a list, because you can access the attributes by name rather than by index:
>>> comp = Company('jhon', 'abc', 'wa@gmail.com')
>>> comp.manager_name
'jhon'
>>> comp.owner_name
'abc'
>>> comp.email
'wa@gmail.com'
If you're lazy and don't want to define the Company
class manually, you can use collections.namedtuple
to reduce the amount of code you have to write:
from collections import namedtuple
Company = namedtuple('Company', 'manager_name owner_name email')
You can also convert your dict of lists to a dict of Company
instances easily:
companies = {10: ['jhon', 'abc', 'wa@gmail.com'],
12: ['raghav', 'awdaw', 'raghavpatnecha15@gmail.com']}
comps = {num: Company(*comp) for num, comp in companies.items()}
# result:
# {10: Company(manager_name='jhon', owner_name='abc', email='wa@gmail.com'),
# 12: Company(manager_name='raghav', owner_name='awdaw', email='raghavpatnecha15@gmail.com')}