[Solved] how to merge a number of lists in to one list [duplicate]

You can do: old_list = [ [‘ID 1d6b:0002’], [‘ID 1d6b:0002’], [‘ID 1d6b:0001’], [‘ID 1d6b:0001’], [‘ID 1d6b:0001’], [‘ID 1d6b:0001’], [‘ID 1d6b:0001’], [‘ID 0b38:0010’], [‘ID 093a:2510’]] new_list = [x[0] for x in old_list] This uses list comprehension to create a new list that contains the first elements ([0]) all on the lists in the old list. Hope … Read more

[Solved] Why does python give me a TypeError for this function? (new to coding) [closed]

You’ve used the same name, list, for both a built-in type and a local variable. Don’t re-use the built-in names. Quoting PEP-8: If a function argument’s name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thus class_ is better than … Read more

[Solved] Getting all ordered sublists of ordered lists

from itertools import combinations, permutations perm=[] index = [9,7,6,5,2,10,8,4,3,1] perm.append(index) M = 3 slicer = [x for x in combinations(range(1, len(index)), M – 1)] slicer = [(0,) + x + (len(index),) for x in slicer] result = [tuple(p[s[i]:s[i + 1]] for i in range(len(s) – 1)) for s in slicer for p in perm] 1 … Read more

[Solved] how to save file image as original name

The reason you have the error is because the lists made by glob and os.listdir are not the same, either different files (glob is only getting jpg files and listdir gets everything) or different order, or both. You can change the filenames in a list, orig_files, to make a corresponding list of new filenames, new_files. … Read more

[Solved] Python Instagram Auto logger

I have rewrote your code a little bit and it works now: from selenium import webdriver from getpass import getpass from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC chromedriver = “C:\\Users\\Utente\\Desktop\\chromedriver” driver = webdriver.Chrome(chromedriver) usr = input (“Enter Your Email: “) psw = getpass(“Enter Your Password: “) prfl = … Read more

[Solved] Convert flat list to dictionary with keys at regular intervals [closed]

Here’s a straightforward solution with a simple loop: dict_x = {} for value in list_x: if isinstance(value, str): dict_x[value] = current_list = [] else: current_list.append(value) Basically, if the value is a string then a new empty list is added to the dict, and if it’s a list, it’s appended to the previous list. solved Convert … Read more

[Solved] i don’t know why this code is writing empty rows on my csv file when using a PC but not on a Mac

You need to specify the newline character when you open the file. On Windows, the default ends up adding an extra ‘\r’. with open(‘quotes.csv’, ‘a’, newline=”\n”) as myFile: writer = csv.DictWriter(myFile, fieldnames=fieldnames) … 1 solved i don’t know why this code is writing empty rows on my csv file when using a PC but not … Read more

[Solved] Keep getting math domain error [closed]

As others said, you should call sqrt() only with proper values. So better do … #Check discriminant discrim = float((bval**2)-(4*aval*cval)) if float(discrim >= 0): # now it is ok to calculate the roots… root1 = – bval + math.sqrt(discrim) root2 = – bval – math.sqrt(discrim) if float(discrim > 0): print (“Roots at:”, root1, root2) else: … Read more