Hey everyone,

I have the following data set

A B C D E
F G H I J
K L M N O
P Q R S T

Where every ten lines or so (though not a regular pattern) the data breaks its format and two of the data pieces get lumped together without a tab delimiter. I don't have the code to work with, only the data itself. I'd like to write a code which essentially scans through the set, and when it finds that there is no tab space between two elements, it inserts one and continues.

My initial inkling would be to write all of the elements into a blank array and then scan the array for the absence of a tab character; however, I have no idea how to tell python to scan for a missing character and I also don't know how to tell python to look for a "tab" in general. E.G.: what is the command for a tab, '\t' or something of the like?

Thanks.

My data set actually formatted correctly when I posted it lol let me try again:

A B C D
E F G H I
J K L M

Sorry, have to put it into code format to see the error:

A                            B                               C                               D                              E
F  G                           H                                 I                               J
K                            M                               N                              O                              P

Ok, no matter what I do, I can't get the data to appear as it does in my data file. Sorry, is the issue clear from my explanation?

Is the data seperated using only spaces and tabs?

If so, try using string replacement (I don't know the phyton syntax) and replace every sequence of 1 or more tab or space-char with a tab-char.

A regular expression might look something like this: ([\t ]+)

Is the data seperated using only spaces and tabs?

If so, try using string replacement (I don't know the phyton syntax) and replace every sequence of 1 or more tab or space-char with a tab-char.

A regular expression might look something like this: ([\t ]+)

Hmmm but I need to insert tabs where they are missing, you know what I mean? I need the code to recognize that text has been squished together and in those spots, separate them. Maybe something like tell the program to search for white spaces of length 2 or less. If found, delete them and replace by tab. How would one do that?

I think you can do that with the same technique. Only change the regular expression to search for strings of 1 or 2 spaces.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.