[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] 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] 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] Ask the user for its name using raw_input [closed]

This is one of the easiest problem ever. This is my solution (since you tagged your post for Python 3): name = input(‘Enter your name: ‘) print(“Welcome”, name) For Python 2, just change input to raw_input, and remove the parenthesis of the print function. 1 solved Ask the user for its name using raw_input [closed]

[Solved] Find same elements in a list, and then change these elemens to tuple (f.e. 2 to (2,1))

To just add a count you could keep a set of itertools.count objects in a defaultdict: from itertools import count from collections import defaultdict counters = defaultdict(lambda: count(1)) result = [(n, next(counters[n])) for n in inputlist] but this would add counts to all elements in your list: >>> from itertools import count >>> from collections … Read more

[Solved] Swap two numbers in list of tuples (python)

For anyone curious, I quickly wrote a function for it. First off, the complete matching is written as a 2D list. The following function is needed before writing the main one: def index_2d(myList, v): #Returns tuple containing the position of v in the 2D list for i, x in enumerate(myList): if v in x: return … Read more