list or dictionary

Ganesh Pal ganesh1pal at gmail.com
Tue Sep 20 14:04:41 EDT 2016


I am on python 2.7 and Linux

I have the stdout in the below form , I need to write a function to get
hostname for the given id.


Example:

>>> stdout
'hostname-1 is array with id 1\nhostname-2 is array with  id 2\nhostname-3
is array with id 3\n'


def get_hostname(id)
       return id

what's a better option here

1. store it in list and grep for id and return
2. store it in dict as key and value i.e hostname = { 'hostname1': 1} and
return key
3. any other simple options.



Regards,
Ganesh



More information about the Python-list mailing list