From e0548e7fdf742da81c2e2932c1194348293c7acf Mon Sep 17 00:00:00 2001 From: Milan Straka <milan@strakovi.com> Date: Fri, 10 May 2019 10:21:42 +0200 Subject: [PATCH] Explicitly show how to iterate over the data in the comment. --- 11-find_duplicates/cpp/find_duplicates.h | 8 ++++++-- 11-find_duplicates/python/find_duplicates.py | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/11-find_duplicates/cpp/find_duplicates.h b/11-find_duplicates/cpp/find_duplicates.h index bea6bbf..5c94a6c 100644 --- a/11-find_duplicates/cpp/find_duplicates.h +++ b/11-find_duplicates/cpp/find_duplicates.h @@ -5,8 +5,12 @@ vector<string> find_duplicates(DataGenerator& generator) { * Find duplicates in the given data. * * The `generator` provides a forward iterator over strings - * for traversing the data (so it can be iterated for example - * using a `for` cycle). It can be traversed multiple times. + * for traversing the data, so it can be iterated for example + * using a `for` cycle: + * + * for (const string& item : generator) {...} + * + * The `generator` can be traversed multiple times. * * The goal is to return a vector of duplicated entries, * reporting each duplicated entry only once, in the order diff --git a/11-find_duplicates/python/find_duplicates.py b/11-find_duplicates/python/find_duplicates.py index 62eacce..e176dbe 100644 --- a/11-find_duplicates/python/find_duplicates.py +++ b/11-find_duplicates/python/find_duplicates.py @@ -4,9 +4,12 @@ import sys def find_duplicates(data_generator): """Find duplicates in the given data. - The data_generator is an `iterable` (it can be iterated over in a for cycle, - or passed to `iter` method to explicitly generate an iterator) returning - strings. It can be iterated multiple times. + The `data_generator` is an iterable over strings, so it can be + iterated for example using a `for` cycle: + + for item in data_generator: ... + + It can be iterated multiple times. The goal is to return a list of duplicated entries, reporting each duplicated entry only once, in the order of their first occurrence in the data. -- GitLab