* Do not use capitalization for function name this violates idiomatic python naming conventions ([PEP8 link](https://www.python.org/dev/peps/pep-0008/#function-names)). Try out pylint to catch these kinds of issues * Prefer `str.format()` over concatenation. `str.format()` is not only a lot more flexible, but easier to use than concatenation and more efficient for combining more than 2 strings. `str.format()` you do not need to explicitly convert objects to the string type. (less `TypeError` exceptions) Instead of `str(name) + ".jpg"` do `"{}.jpg".format(name)` * Use sub functions to break up your code. This function is on the larger side. * Prefer iteration over indexing. A `list` or any container can be iterated over to yield its contents. For example do `for link in links_list:` instead of `while k <= (len(links_list) - 1):` Randomly picking a filename is decidedly not a good idea. The given filename may already exist, and urlretrieve will go ahead and overwrite the file. Here's would be an example function for retrieving a unique filename. def unique_filename(): """Yield a unique filename. The given filenames start at 0.jpg, 1.jpg and so on """ # type: Iterable[str] for filenum in count(): filepath = "{}.jpg".format(filenum) if not os.path.exists(filepath): yield filepath then you could do something like: for link, filename in zip(links_list, unique_filename()): urllib.urlretrieve(link, filename) We use a generator to yield only filenames that do not exist, and use the finite `links_list` to limit the generator since `zip` stops when the first iterable is exhausted. As a side note, `links_list` is a very redundant name. A list implies multiple. I (and [Brandon Rhodes](https://www.youtube.com/watch?v=YklKUuDpX5c)) would rather name it `link_list`. If this was ruby, you would want to just name it `links`.