-1

I am looking to produce a list which contains strings all in the form of URL's I cannot figure out how to produce a list of strings.

I have tried creating a function that will concat some static values together along with a dynamic variable (ranging from 1-8), with the end goal producing URL's in the form http://www.omdbapi.com/?apikey=blah=shameless&Season=1&Episode=2, http://www.omdbapi.com/?apikey=blah=shameless&Season=2&Episode=2, and so on, with the Season= being the value I want to range from 1-8 incrementing by one.

The code I am using is

def numbers():
    for n in range (1,9):
        print (str(url+movie+'&Season='+str(n)+'&Episode=2'))

abc = numbers()

print(abc)

which produces

http://www.omdbapi.com/?apikey=blah=shameless&Season=[1, 2, 3, 4, 5, 6, 7, 8]&Episode=2

Again, I want a list of 8 strs, not a single str containing the 8 values I were hoping would represent the different element of each string.

Any help or a nudge in the right direction would be great!

sappgob
  • 27
  • 2
  • 2
    Strange, when I run your code (after defining values for `url` and `movie`), I don't get `http://www.omdbapi.com/?apikey=blah=shameless&Season=[1, 2, 3, 4, 5, 6, 7, 8]&Episode=2`. I get `google.com/avengers&Season=1&Episode=2`, and `google.com/avengers&Season=2&Episode=2`, etc up to `google.com/avengers&Season=8&Episode=2`, and then `None`. Are you sure this is the code you're running? – Kevin Apr 29 '19 at 18:21
  • 1
    Your function returns None. Perhaps you need to return a list comprehension. – quamrana Apr 29 '19 at 18:22

1 Answers1

0

try list comprehension, below code should work for you.

def numbers():
    return [str(url+movie+'&Season='+str(n)+'&Episode=2')     for n in range (10) ]

abc = numbers()

print(abc)
mkrana
  • 422
  • 4
  • 10