Skip to content

Instantly share code, notes, and snippets.

@abhitheawesomecoder
Last active December 22, 2024 14:03
Show Gist options
  • Select an option

  • Save abhitheawesomecoder/66d0d112e360c9def237819de40c7028 to your computer and use it in GitHub Desktop.

Select an option

Save abhitheawesomecoder/66d0d112e360c9def237819de40c7028 to your computer and use it in GitHub Desktop.
List<int> listWithoutDuplicate = [1,2,3,4];
List<String> listWithDuplicate = ['a','b','a'];
Map<dynamic,int> frequencyCount(List<dynamic> itemList){
Map<dynamic,int> uniqueList = {};
for(var item in itemList){
if(uniqueList.containsKey(item)){
uniqueList[item] = uniqueList[item]! + 1;
}
else{
uniqueList[item] = 1;
}
}
return uniqueList;
}
void main() {
frequencyCount(listWithoutDuplicate).forEach((key,value){
print([key,value]);
});
print('*********');
frequencyCount(listWithDuplicate).forEach((key,value){
print([key,value]);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment