List indexing and removing elements.
I was doing an exercise where to goal is to take one string and put all the caps characteres at the beginning of the string. My first solution was : y = 'AbDeULDSAF asdfGeeGGG' d = list(y) v =  for e in d: h = d.index(e) if e != e.lower(): v.append(e) del d[h] p = v+d l = ''.join(p) print(l) Output : ADUDAGGGbeLSF asdfeeG So some of the cap character were missed. I guess that deleting a charactere in the list was modifying the indexing dynamically ( logical because if you remove an element the indexing change) I solved the issue with doing two new lists, one for the small charactere and one for the caps. y = input('enter a string') d = list(y) v =  t =  print(d) for e in d: h = d.index(e) if e != e.lower(): v.append(e) else: t.append(e) p = v+t l = ''.join(p) print(l) This time seems to be working fine. I am still looking at way to do this by creating only one list. I will try to stock the index value first, then in another loop use those index value to remove the elements in one go.