I’ve been working on learning python and somehow came up with following codes:
for item in list:
while list.count(item)!=1:
list.remove(item)
I was wondering if this kind of coding can be done in c++. (Using list length for the for loop while decreasing its size) If not, can anyone tell me why?
Thanks!
I am not a big Python programmer, but it seems like the above code removes duplicates from a list. Here is a C++ equivalent:
As for modifying the list while iterating over it, you can do that as well. Here is an example:
Hope it helps.