I have the following three lines (they exist independently, but are displayed here together for convenience):
from mx2.x.org (mx2.x.org. [198.186.238.144]) by mx.google.com with ESMTPS id g34si6312040qgg.122.2015.04.22.14.49.15 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 Apr 2015 14:49:16 -0700 (PDT) from HQPAMAIL08.x.org (10.64.17.33) by HQPAMAIL13.xxorg (10.34.25.11) with Microsoft SMTP Server (TLS) id 14.2.347.0; Wed, 22 Apr 2015 17:49:13 -0400 from HQPAMAIL13.x.org ([fe80::7844:1f34:e8b2:e526]) by HQPAMAIL08.iadb.org ([fe80::20b5:b1cb:9c01:aa86%18]) with mapi id 14.02.0387.000; Wed, 22 Apr 2015 17:49:12 -0400
I am looking to fill a dict with some values based on the reverse (bottom) line order. In particular, for each row, I retrieve the IP address as a sorting index, and then the full string as a value.
Given that order is important, I decided to go with the lists and first did something like this (pseudocode, with the text above):
IPs =[] fullStrings =[] for string in strings: IPs.append[$theIpAddressFoundInTheString] fullstrings.append[$theWholeString]
resulting in the following two lists (again, just an illustration):
IPs ['198.186.238.144', '10.64.17.33', 'fe80::7844:1f34:e8b2:e526'] fullstrings ['from mx2.x.org (mx2.x.org. [198.186.238.144]) by mx.google.com with ESMTPS id g34si6312040qgg.122.2015.04.22.14.49.15 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 22 Apr 2015 14:49:16 -0700 (PDT)', 'from HQPAMAIL08.x.org (10.64.17.33) by HQPAMAIL13.xxorg (10.34.25.11) with Microsoft SMTP Server (TLS) id 14.2.347.0; Wed, 22 Apr 2015 17:49:13 -0400', 'from HQPAMAIL13.x.org ([fe80::7844:1f34:e8b2:e526]) by HQPAMAIL08.x.org ([fe80::20b5:b1cb:9c01:aa86%18]) with mapi id 14.02.0387.000; Wed, 22 Apr 2015 17:49:12 -0400']
This worked fine until the moment, but now when I start filling in the dict values with the values in these lists (by hardcoded indexes), comparing them with the values in other lists (again by hardcoded indexes), etc., Not only does debugging become a pain, but code becomes unstable.
I am starting to rewrite with dict (returning a dict where IP addresses are keys and full strings are values). Then I will perform operations such as:
for k,v in myDictOfIpsAndStrings: anotherDict[$someHardcodedText] = k anotherDict[$otherHardcodedText] = v
Here is my concern: Can I be sure that the dict, at any time when it repeats, will always be executed in the order in which the dict was created? If not, is this my only option to return to lists (and tedious and fragile length comparisons, assignments inherent in this), etc.?
I know that a dict is inherently unsorted. And I know the sorted function, but I don’t want to sort their keys in descending / ascending order, etc., Namely, to maintain (somehow) the order in which the dict was created.