2016년 12월 13일 화요일

MIT App Inventor 2 Count the duplicates in a list


I have to, maybe a easy question, if possible reading how many items in the list , are equal ?

--
If what you need is the list filtered with no duplicates, may be a faster way to do it would be to save each item of the list as a tag in TinyDB and then reload the list with all the tags saved. Since the duplicates will be overwritten, you will have no duplicates.
I just thought of that, and I just woke up ;-) so maybe there's a better way. Any ideas?

-- 
Now if you need to know exactly how many duplicates you have for each one, you can check first, if the tag already exists, add 1 to the number saved in that tag, if not, just create the tag.

--
Many thanks for the quick response, the need is the number of duplicates have the list, you can see my picture (List Home). I honestly do not understand how you suggest to do . Can you please post a image within a example ?

-- 
I filtered with no duplicates with ( For each ) procedure  ....
-- 
Do you know how to use TinyDB? 

Delete all the tags in TinyDB
Use a for each to run the whole list.
Ask if the current item in the for each exists as a tag
If it doesn't exist, create it (Tag = element in the list and value = 1)
If it exists, that means is a duplicate and was created before, so the value must be increased in 1. 

After the for each ends, you can show each tag and its values when the value is > 1. That will give you only the duplicates and how many times is that item in the list.
Of course you can do it with a procedure, but I think using this TinyDB methid it will be faster, especially if the list is big.

-- 
Here are two examples of how to REMOVE duplicates from a list  https://groups.google.com/forum/#!msg/mitappinventortest/j1GukExhQ1k/vnnRTzDDctAJ;context-place=category-topic/mitappinventortest/l8EMUJz_jHk      Perhaps you can modify one of them to count as it removes duplicates.  I think this will modify the original list so you would have to retain a copy of the original list...there is a block to do that.

Try it.   You do not have to use a TinyDB to count the duplicates.

Merry Christmas, Wesołych Świąt,  Feliz Navidad, God Jul, Joyeux Noel, Καλά Χριστούγεννα, Happy Christmas, Veseloho Rizdva, Prettige Kerstdagen, Frohe Weihnachten!, 성탄 축하 , Buon Natale,  聖誕快樂 ,  圣诞快乐,  Sretan Božić, C рождеством!,  عيد ميلاد مجيد

-- 
One of the examples is exactly my procedure to remove duplicates, using two different Lists (List BEFORE ) and (List AFTER) .
After that i use the ( List AFTER ) to populate a ( List Picker ) .
I need to use e (ListPicker Selection) to know how many items , inside to the (List Before) ,  are present with the same value / name .
I do not know how to count how many time , in the procedure ( For Each ) it read the same value/ name  .

-- 
length of list block tell you how many items are in a list, so, if you have a copy of the before and after lists (List BEFORE and List AFTER ... whatever you name them), use the block length on each and subtract one from another = numbers of duplicates perhaps?     

To count in a procedure Ivo,  normally you would and a variable called counter and increment it by one each time you loop.    perhaps try that if you do not want to compare the 'length of two lists"

Just try some things.  Any luck?

-- 


댓글 없음:

댓글 쓰기