-1

Initially, i have a list of lists containing, for example

L = [[01,02],[03,04],[05,06]]

and for each of the individual list within the list of list, my program does some calculation from the elements within the list and had the values output in a single list.

OutputList = [2.1,2.2,2.3]

the value 2.1 corresponds to [01,02], 2.2 corresponds to [03,04] and finally 2.3 corresponds to [05,06]

i want to print out the outputList and also the individual list corresponding to the value in the output list something like as below.

2.1 : [01,02]
2.2 : [03,04]
2.3 : [05,06]

I would like to know how i would be able to get the output as such. I know i should utilise for loops to perform something like:

for val in OutputList:
    for lst in L:
        OutputList[val] == L[lst] ##??
Maxxx
  • 3,688
  • 6
  • 28
  • 55
  • 4
    Possible duplicate of [How can I iterate through two lists in parallel in Python?](http://stackoverflow.com/questions/1663807/how-can-i-iterate-through-two-lists-in-parallel-in-python) – juanpa.arrivillaga Apr 24 '17 at 06:02

2 Answers2

0

You can use enumerate to iterate list values with index

for ind, val in enumerate(outputList):
    print('{} : {}'.format(val, L[ind])
Hou Lu
  • 3,012
  • 2
  • 16
  • 23
0

You can zip two lists together like zip(outputList,L) and it will create tuples like (2.1,[01,02]) , you can just print the list as below:

zipped =zip(outputList,L)
for item in :
     print ("{} : {}".format(zipped[0],zipped[1])) 
Pushkr
  • 3,591
  • 18
  • 31