Avatar ·

Difference of lists in Python [duplicate]

📁 список, вопрос, пример

(4 answers)
Closed 7 years ago.

There are three lists: list1, list2 and list3.

It is known that list1 > list2 (by number of elements), and list3 is empty.

It is also known that the first elements of list1 and list2 are the same (for example, list1 = [Vasya, Petya, Masha, Sasha], and list2 = [Vasya, Petya]).

Task: fill list3 with the difference of the first and second lists, i.e. in the given example list3 = [Masha, Sasha].

Avatar ·

urllib -> urlopen - opens a file at the given URL for reading, then you can simply read() it, open a file for binary writing, and write to it what you read via HTTP. Example of downloading a logo:

import urlliblogo = urllib.urlopen("http://www.google.com/images/srpr/logo3w.png").read()f = open("logo3w.png", "wb")f.write(logo)f.close()

There is also urllib.urlretrieve(url, [filename,[...]]) - in my opinion its purpose is specifically for downloading.

import urllibdestination = 'logo3w.png'url = 
                            

Log in to leave an answer

Blogs