0

I have to variables one="{}{}{}T{}:{}:{}" and two='2021,-10,-28,05,40,33' When i try to use print(one.format(two)) i am getting errors. IndexError: Replacement index 1 out of range for positional args tuple. guessing it is because the two variable is being seen as a string. So I switched and tried to do the *args method.

for item in two:
  item = str(item)
  data[item] = ''
result = template.format(*data)

However if I switch two='2021,-10,-28,00,00,00.478' it fails because a dictionary is unique. so how do i get the first method to work or is there a better solution.

1 Answer 1

3

You should split the two into list and then unpack it with *

one="{}{}{}T{}:{}:{}"
two='2021,-10,-28,05,40,33'

print(one.format(*two.split(','))) # 2021-10-28T05:40:33
Sign up to request clarification or add additional context in comments.

1 Comment

You are a genius. Didn't ever cross my mind.

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.