There is the following list of proxy servers:

['1.2.3.4:80', '12.13.14.15:3128', '123.123.123.123:8080'] 

How to make sure that all IP-addresses are in the following list:

 proxies = {'http': '1.2.3.4:80', 'http': '12.13.14.15:3128', 'http': '123.123.123.123:8080'} 

I know that it is necessary to load the cycle with for , but how exactly I can’t figure it out.

  • four
    Do you really need a dictionary with duplicate keys? - user194374
  • @kff this is required by the Requests documentation, with which I send GET requests. - JamesJGoodwin
  • 6
    You misunderstood the documentation. There can be only one proxy for one protocol, i.e. one for http, one for https, etc. - user194374
  • also proxies you have a dictionary (not a list), which is: {'http': '123.123.123.123:8080'} (the last value among duplicate keys in a constant (dict view) wins). - jfs

1 answer 1

The task of bringing the list to the dictionary with the same key does not have a solution, since

the key must be unique ; if, nevertheless, we try to do this, we will get only the last value.

Example.

 >>> {'http': '1.2.3.4:80', 'http': '12.13.14.15:3128', 'http': '123.123.123.123:8080'} {'http': '123.123.123.123:8080'} 

a dictionary with duplicate keys does not exist by definition. At different levels may be the same keys, but not on one. One will be overridden by subsequent ones.