Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Comparing two lists and finding indices of changes Dart

What is cleanest way to compare two list and find out different index, example:

list1 = ['M', 'A', 'N', 'H', 'T', 'U', 'A', 'N']
list2 = ['M', 'I', 'N', 'H', 'T', 'O', 'A', 'N']

How to get different index list [1, 5]

I was trying to loop each list, but it seem pretty awkward, is there any collection fuction to do this ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could do this:

final result = IterableZip([list1, list2])
    .mapIndexed((index, element) => element[0] != element[1] ? index : null)
    .whereNotNull()
    .toList();

This needs

import 'package:collection/collection.dart';
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading