list

Fastest Proxy Iteration in Python

孤者浪人 提交于 2021-02-17 06:10:14
问题 Let's say I have a list that contains 10,000+ proxies proxy_list = ['ip:port','ip:port',.....10,000+ items] How do I iterate it to get the proxies that works for my pc? Using the following code it is possible to find it , but takes 5*10,000 seconds to get completed. How would I iterate through the list faster? import requests result=[] for I in proxy_list: try: requests.get('http:\\www.httpbin.org\ip',proxies = {'https' : I, 'http' : I } ,timeout = 5) result.append(I) except: pass 回答1: You

Print list to txt file without [brackets] in PYTHON

混江龙づ霸主 提交于 2021-02-17 05:37:27
问题 I am trying to take a list of names, alphabetize them and print them to a new list. Here is my code: names = [] newnames = [] with open("C:/names.txt", "r") as infile: for row in infile.readlines(): name = row.split() names.append(name) for x in sorted(names): newnames.append(x) print newnames f = open("C:/newnames.txt", "w") f.write("\n".join(str(x) for x in newnames)) f.close() my problem is that it prints fine except for the brackets: ['Bradley'] ['Harold'] ['Jackson'] ['Lincoln'] [

Print list to txt file without [brackets] in PYTHON

穿精又带淫゛_ 提交于 2021-02-17 05:37:09
问题 I am trying to take a list of names, alphabetize them and print them to a new list. Here is my code: names = [] newnames = [] with open("C:/names.txt", "r") as infile: for row in infile.readlines(): name = row.split() names.append(name) for x in sorted(names): newnames.append(x) print newnames f = open("C:/newnames.txt", "w") f.write("\n".join(str(x) for x in newnames)) f.close() my problem is that it prints fine except for the brackets: ['Bradley'] ['Harold'] ['Jackson'] ['Lincoln'] [

List assignment in python

纵饮孤独 提交于 2021-02-17 05:32:06
问题 I have a code like below,when i print the list1 and list2 it shows same elements but i have added the 9 after the assignment of existing list1 to list2 so it should not show 9 in list2. list1=[1,2,3,4] list2=list1 list1.insert(4,9) print(list1) print(list2) please clear my doubt. 回答1: In python, a variable name is a reference to the underlying variable. Both list1 and list2 refer to the same list, so when you insert 9 into that list, you see the change in both. You need to make an explicit

TypeError: unsupported operand type(s) for +: 'int' and 'str' when using str(sum(list))

血红的双手。 提交于 2021-02-17 05:24:42
问题 I'm going through the Python tutorial and have no idea why my code isn't working. I know I need to tell Python to print an integer manually but I have already put str(sum(ages)) . Can anyone tell me why this is happening? ages = ['24','34','51','36','57','21','28'] print('The oldest in the group is ' + str(max(ages)) + '.') print('The youngest in the group is ' + str(min(ages)) + '.') print('The combined age of all in the list is ' + str(sum(ages)) + '.') Error: File "list2.py", line 4, in

Combine Python List and Dict comprehension with counter

僤鯓⒐⒋嵵緔 提交于 2021-02-17 02:22:30
问题 I want to transfer a list of tuples: [(1, 3, 5), (2, 4, 6), (7, 8, 9)] to a list of dict (in order to create a pandas dataframe) which looks like: [{'index':1, 'match':1},{'index':1, 'match':3},{'index':1, 'match':5}, {'index':2, 'match':2}, {'index':2, 'match':4},{'index':2, 'match':6}, {'index':3, 'match':7},{'index':3, 'match':8},{'index':3, 'match':9}] For performance reasons I wanted to use a list and dict comprehension: [{'index':ind, 'match': } for ind, s in enumerate(test_set, 1)] How

How I can access array elements of List

旧城冷巷雨未停 提交于 2021-02-16 22:46:51
问题 I have a question: I have a List Java that I have populated with different values. For example, I have: List<String[]> l = new ArrayList(); String[] lis = new String[3]; lis[0] = "A"; lis[1] = "B"; lis[2] = "C"; l.add(lis); and I have other values too. Now, I want to get the search in this list only the first field. For example, I want the A's indexOf. I have tried to write this code: int index = l.indexOf("A"); but I get -1 as return. I would like to know how I can access to a field of the

How I can access array elements of List

懵懂的女人 提交于 2021-02-16 22:45:30
问题 I have a question: I have a List Java that I have populated with different values. For example, I have: List<String[]> l = new ArrayList(); String[] lis = new String[3]; lis[0] = "A"; lis[1] = "B"; lis[2] = "C"; l.add(lis); and I have other values too. Now, I want to get the search in this list only the first field. For example, I want the A's indexOf. I have tried to write this code: int index = l.indexOf("A"); but I get -1 as return. I would like to know how I can access to a field of the

How I can access array elements of List

浪尽此生 提交于 2021-02-16 22:45:20
问题 I have a question: I have a List Java that I have populated with different values. For example, I have: List<String[]> l = new ArrayList(); String[] lis = new String[3]; lis[0] = "A"; lis[1] = "B"; lis[2] = "C"; l.add(lis); and I have other values too. Now, I want to get the search in this list only the first field. For example, I want the A's indexOf. I have tried to write this code: int index = l.indexOf("A"); but I get -1 as return. I would like to know how I can access to a field of the

TypeError: list indices must be integers or slices, not float

故事扮演 提交于 2021-02-16 20:45:07
问题 def convBin(): cont = [] rest = [] dev = [] decimal = [] print("Ingrese el valor a convertir: ") valor = ast.literal_eval(input()) if isinstance(valor, int): while valor > 0: z = valor // 2 resto = valor%2 valor = valor // 2 cont.append(z) rest.append(resto) cont.reverse() rest.reverse() dev.append(cont[0]) x = 0 while x <= (len(rest) - 1): dev.append(rest[x]) x += 1 print(" ") print("Lista de devoluciones: ") print(dev) print("") elif isinstance(valor, float): a = valor // 1 b = valor % 1