Python Forum
Adding spaces to digits
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding spaces to digits
#3
@deadkill02

For the rest of this task, I would create a 'new tokens' list object, then nest two for loops; one to loop through the existing tokens, and the other to loop though the numbers (which will be string objects, don't forget) within the tokens:

for token in ccn_lst:

for index, item in enumerate(token):

In the first loop, create a 'new token' string: new_token = ""
In the second loop, have an if/else branch the checks the index number in range(1, 4, 2) and build up the 'new_token' string, from that branch.
Do you know why I have (1, 4, 2)?

When that's done, .append() the 'new token' to the 'new tokens' list, at which point, the second loop is finished and the first loop will grab the next token in the 'ccn_lst'.

It is in fact, far more work to describe this as I have, than it is to write the code, but give it a shot and if you get stuck, simply post back with what you have and I'll guide you some more.
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
Reply


Messages In This Thread
Adding spaces to digits - by deadkill02 - Feb-08-2024, 08:12 PM
RE: Adding spaces to digits - by rob101 - Feb-08-2024, 09:22 PM
RE: Adding spaces to digits - by rob101 - Feb-09-2024, 04:51 PM
RE: Adding spaces to digits - by deanhystad - Feb-09-2024, 07:29 PM
RE: Adding spaces to digits - by Pedroski55 - Feb-10-2024, 07:02 AM
RE: Adding spaces to digits - by rob101 - Feb-10-2024, 01:08 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020