0

I am trying to loop my database output and get the result of each loop as variable with following code.

for item in output:
    v=''.join(item)
    link="https://example.com/user/{}".format(v)
    print(link)

I already tried to put that in a variable with:

var=for item in output:
    v=''.join(item)
    link="https://example.com/user/{}".format(v)
    print(link)

but that did not work

3
  • It's unclear what you're asking, but probably you want to initiate an empty list or dictionary before the loop that you can then fill during the loop Commented Apr 10, 2019 at 15:36
  • Are you trying to get all the items into one variable, after that create the link and print it ? Commented Apr 10, 2019 at 15:39
  • @ionut exactly, that was my goal. The answer below did work for me. Thank's for your help Commented Apr 10, 2019 at 15:41

1 Answer 1

4

You might mean that you want a list of links:

var = ["https://example.com/user/{}".format(''.join(item)) for item in output]
Sign up to request clarification or add additional context in comments.

1 Comment

Pythonic is the way

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.