0

I have the following tuple value and wanted to split single tuple value into multiple values.I tried converting the tuple to string and used split(),splitlines() based on \n as delimiter however it didn't work.Any inputs please?

INPUT:
('2018-10-23\n2018-10-25\n2018-10-26\n2018-10-27\n2018-10-28\n2018-10-30\n', 0)

OUTPUT:
2018-10-23
2018-10-25
2018-10-27
2018-10-28
2018-10-30
2
  • Please give a minimal reproducible example, what exactly do you mean by "didn't work"? Commented Nov 28, 2018 at 20:37
  • Is the output supposed to be a list? Commented Nov 28, 2018 at 20:40

2 Answers 2

1

You need to split the first element of the tuple:

inpt = ('2018-10-23\n2018-10-25\n2018-10-26\n2018-10-27\n2018-10-28\n2018-10-30\n', 0)

result = inpt[0].strip().split()

for e in result:
    print(e)

Output

2018-10-23
2018-10-25
2018-10-26
2018-10-27
2018-10-28
2018-10-30
Sign up to request clarification or add additional context in comments.

Comments

1

If you want a list, you can use str.splitlines. If you want the output you posted on the screen... just print it.

>>> inp = ('2018-10-23\n2018-10-25\n2018-10-26\n2018-10-27\n2018-10-28\n2018-10-30\n', 0)
>>> 
>>> inp[0].splitlines()
['2018-10-23',
 '2018-10-25',
 '2018-10-26',
 '2018-10-27',
 '2018-10-28',
 '2018-10-30']
>>> 
>>> print(inp[0], end='')
2018-10-23
2018-10-25
2018-10-26
2018-10-27
2018-10-28
2018-10-30

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.