Can post a code but afraid of plagiarism
Emile van Sebille
emile at fenx.com
Thu Jan 23 16:28:54 EST 2014
On 1/23/2014 1:15 PM, indar kumar wrote:
> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote:
>> Hi,
>>
>>
>>
>> I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public
>
> hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}],'PC1':['01:01:01:01:01:01', '192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531), '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}
>
>
> Hi,
> I want to print a value before a particular value inside of a list associated with a key inside main dictionary(hosts) not the one inside nested dictionary.
>
> Forexample,
> I want the user to input ip e.g. 192.168.0.2 and then search through dictionary print MAC e.g.02:02:02:02:02:02 that is just before that IP. Note that host id(e.g.PC2) is not known user just inputs IP.
>
Like this?:
>>> hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200',
... {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}],
... 'PC1':['01:01:01:01:01:01', '192.168.0.1', '200',
... {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531),
... '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}
>>>
>>> searchfor = '192.168.0.1'
>>>
>>> print [ ii[0] for ii in hosts.values() if ii[1] == searchfor ]
['01:01:01:01:01:01']
More information about the Python-list
mailing list