Jun-21-2017, 10:06 PM
(Jun-20-2017, 06:08 PM)DeaD_EyE Wrote:(Jun-20-2017, 09:49 AM)bencouve Wrote: Perfect! Thanks ...
and ok
first post
Please don't do this. You're using the wrong data structure. Maybe you want to have a dict:
data = {'i0': 'This', 'i1': 'is', 'i2': 'the', 'i3': 'string'} # direct access print(data['i0']) # iterating over values # unordered for value in data.values(): print(value) # sorted access # sorted sorts by first element, if the the yielded element is a list/tuple for key, value in sorted(data.items()): print(value) # or preserve the order: from collections import OrderedDict data = [('i0', 'This'), ('i1', 'is'), ('i2', 'the'), ('i3', 'string')] ordered_dict = OrderedDict(data) for value in ordered_dict.values(): print(value)Since Python 3.6 dicts preserve the order, but we should not rely on it. Maybe with next version they guarantee it.
Currently it's just an implementation detail.
... or even simpler, an array:
i = [ 'This','is','the', 'string' ] # Stylistically `i` is a bad name for an array # direct access print(i[0]) # iterating over value (always ordered) for value in i: print(value)
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Your one-stop place for all your GIMP needs: gimp-forum.net