Hi I have been reading up about regular expressions, I have got some basic res working. I now have been trying to use Re to sort out data like this:
"144,1231693144,26959535291011309493156476344723991336010898738574164086137773096960,26959535291011309493156476344723991336010898738574164086137773096960,1.00,4295032833,1563,2747941288,1231823695,26959535291011309493156476344723991336010898738574164086137773096960,26959535291011309493156476344723991336010898738574164086137773096960,1.00,4295032833,909,4725008"
...into a tuple but I cannot get it to work.
Can anyone explain how they would go about something like this?
Thanks
You don't want regular expressions here.
s = "144,1231693144,26959535291011309493156476344723991336010898738574164086137773096960,26959535291011309493156476344723991336010898738574164086137773096960,1.00,4295032833,1563,2747941 288,1231823695,26959535291011309493156476344723991336010898738574164086137773096960,26959535291011309493156476344723991336010898738574164086137773096960,1.00,4295032833,909,4725008"
print s.split(',')
Gives you:
['144', '1231693144', '26959535291011309493156476344723991336010898738574164086137773096960', '26959535291011309493156476344723991336010898738574164086137773096960', '1.00
', '4295032833', '1563', '2747941 288', '1231823695', '26959535291011309493156476344723991336010898738574164086137773096960', '26959535291011309493156476344723991336010898
738574164086137773096960', '1.00', '4295032833', '909', '4725008']
How about a list?
mystring.split(",")
It might help if you could explain what kind of info we are looking at. Maybe some background info also?
EDIT:
I had a thought you might want the info in groups of two?
then try:
re.split(r"\d*,\d*", mystring)
and also if you want them into tuples
[(pair[0], pair[1]) for match in re.split(r"\d*,\d*", mystring) for pair in match.split(",")]
in a more readable form:
mylist = []
for match in re.split(r"\d*,\d*", mystring):
for pair in match.split(",")
mylist.append((pair[0], pair[1]))
Question is a little vague.
list_of_lines = multiple_lines.split("\n")
for line in list_of_lines:
list_of_items_in_line = line.split(",")
first_int = int(list_of_items_in_line[0])
etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With