-4

I am having below list:

platform = ['0/0','0/1','0/2','0/3']

from the above list i want to return a value for each item in that list.

if '0/0' in platform:
    return value1
if '0/1' in platform:
    return value2

and so on. but if i use this code it will stop when it finds the first match, for second and third values it will not match.

But i want to check how many items are there in that list and what are they ?and return the respective values for the items present in that list

Alexander Ejbekov
  • 5,594
  • 1
  • 26
  • 26
  • 2
    Possible duplicate of [How to find all occurrences of an element in a list?](https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-list) – Slam Feb 27 '18 at 09:24
  • so what would be your desired output for the example input you posted? – Ma0 Feb 27 '18 at 09:24

1 Answers1

0

Hello Sathya Varna,

I think you are looking for Data Structures/Dictionaries.

If I understand correctly from your description you want to know how many elements you have in your list (e.g. Array), but after that you want to link your list with a value for each element. If this is the case you can link each element (key) with a (value) and create a dictionary.

By doing so you can call a value based on the key.

Sample of code bellow:

#!/usr/bin/env python

dictionary = { 'O/O': 'value1',
               '0/1': 'value2',
               '0/2': 'value3',
               '0/3': 'value4' }

print "Length : %d" % len (dictionary)
print dictionary.keys()
print dictionary.values()
print "dictionary['0/2']: ", dictionary['0/2']

If this is not what you are looking for, provide us more information on what is the expected output.

Hope this helps, BR.

Thanos
  • 1,618
  • 4
  • 28
  • 49