There are a few different ways to do this and your code can be made much more succinct.
This (for example) removes the hyphens and reverses each 'token'. The resulting tokens are replaced, within the same list object.
to add: you could also look into the third perimeter of the
This (for example) removes the hyphens and reverses each 'token'. The resulting tokens are replaced, within the same list object.
ccn = "2323-2005-7766-3554" ccn_lst = ccn.split("-") for index, token in enumerate(ccn_lst): ccn_lst[index] = token[::-1]Have a look into string slicing to see how this works and to complete the rest of your project.
to add: you could also look into the third perimeter of the
range()
function, which is commonly called a 'step': range(start, stop, step)
.
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein