0

How would one change the string "Point" to be a variable input (string)?

result = []
list =  [[a,b,c,d][a,b,c,d]]

result.append( [["Point {}".format(i) for i in range(1, len(sub)+1)] for sub in list])

I basically dont want to use string "Point" as a constant but rather as another parameter value. I tried this:

result = []
list =  [[a,b,c,d][a,b,c,d]]
p_name = "Number"

result.append( [[p_name, {}.format(i) for i in range(1, len(sub)+1)] for sub in list])

I would like to end up with:

result = [[Number 1, Number 2, Number 3, Number 4][Number 1, Number 2, Number 3, Number 4]]

Thank you,

2
  • What is exactly your Number 1, a string, tuple, list? Commented Mar 12, 2014 at 19:19
  • @RubenBermudez String. I am using this to create a matching list to that of an input list, but so that it lists how many items there is in each list. Commented Mar 12, 2014 at 19:50

1 Answer 1

1
result.append( [["{} {}".format(p_name, i) for i in range(1, len(sub)+1)] for sub in list])
Sign up to request clarification or add additional context in comments.

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.