How To Determine Index of Duplicate Items in a List

Hello,
I am new to MIT app inventor.I have been using app inventor or 3 months now.So basically I am making a school project and it requires identification of the position of an item.For example,when the user enters “apple” the app will tell the position of each letter like this"a=1,p=2,p=3,l=4,e=5".However,the problem is when the position of the letter p,it will show “a=1,p=2,p=2,l=4,e=5”.Is this because the index of 2nd “p” in list follows the index of the 1st “p”?

Use the number from-to-by block using the length of your list, instead of the for each item block

1 Like

this looks like a good place to use a dictionary block.
Let the tags be the letters, and the values be lists of indexes in the original word where that letter was found.

Build up the dictionary from empty by examining each letter of the input, to see if it is already in the dictionary. Add the new index into the list in the value for that letter (empty list of not found.)

1 Like

Oh thank you very much…sorry for the late reply.I will try it first👍

Hello…sorry for bothering but can you show how to examine each letter and add in into the dictionary

Here is the procedure:

and a sample call:
letter_indices_test
for the word onomatopoeia, getting the Do It result
Do It Result: {“o”:[1,3,7,9],“n”:[2],“m”:[4],“a”:[5,12],“t”:[6],“p”:[8],“e”:[10],“i”:[11]}

in JSON text representation of the dict object.

All blocks are draggable.