Hi,
I have written the following Python program:
1.a= ["a", "f", "bar", "b","a", "aaaaa"]
2.ind = {a[i]:i for i in range(len(a))}
3.print(ind)
4.print("ind['a']= {0}".format(ind['a']))
5.print("a[5]= {0}, a[4]= {1}, a[3]= {2}, a[2] = {3}, a[1] = {4}, a[0]= {5}".format(a[5],a[4], a[3], a[2], a[1], a[0]))
output is:
Line #1 , I can understand, we are creating an array of 6 elements, starting index is 0 and end index is 5. I can’t understand following things in line#2:
a) what is the purpose of ‘ind’ variabel?
b) What is the purpose of curly bracket in line#2
c)What is the purpose of colon in line#2
d) Which statements are under the impact of ‘for’ loop and how will we know that the scope of ‘for’ loop has ended?
e) There are two enteries for ‘a’ in the array, why I am getting the index for “ind[‘a’] as 4.
Somebody please guide me
Zulfi.