Home > Software engineering >  Why is this approach to print the frequency of each character of a given string not working?
Why is this approach to print the frequency of each character of a given string not working?

Time:01-06

why does the iteration variable a skips the character value 'a' in list and directly moves over to 'd' from 'r'?

CodePudding user response:

Because you have a remove operation while traversing lst in a for loop, the elements in lst are decreasing.

Based on the existing code, you can try to modify for a in lst to for a in lst.copy()

CodePudding user response:

Because after first iteration "a" position is 0 and it take 1st position item i.e "d".

  •  Tags:  
  • Related