loops

Pyhton csv reader: loop over csv files

Pyhton csv reader: loop over csv files Question: I have several csv files that are named: list_csv_X with X going from 0 to 5. I would like to do a loop to read them with Python. I am currently doing it manually: for filepath in list_csv_0: with open(filepath,’r’,encoding="utf8", errors=’ignore’) as csvfile: BLABLABLA for filepath in …

Total answers: 2

Python : removing other appearances of an item in a list

Python : removing other appearances of an item in a list Question: I was triying to make a program that can remove any other appearnces of an item in a list but it seems that there is something that I don’t understand about loops list = [3, 2, 1, 4, 2, 3, 2] list2 = …

Total answers: 4

Print the Number series in Pyhon

Print the Number series in Pyhon Question: Help me to solve this number series question: input : 5 Output: 2 3 4 4 5 6 5 6 7 8 6 7 8 9 10 My program : rows = 6 # number of rows in the pattern start_num = 2 # starting number for the …

Total answers: 3

How to optimize iterating a Dataframe?

How to optimize iterating a Dataframe? Question: I want to groupby dataframe column values based on ID and I have the following: data = { "ID": ["1", "1", "2"], "start": [5, 6, 30], "end": [10,20,50], "label": ["age", "gender", "history"] } df = pd.DataFrame(data) The result i’m looking for is something like this: Dict = {{‘ID’: …

Total answers: 1

Python : Problem recreating replace function

Python : Problem recreating replace function Question: trying to make a string replace function as a beginner(i don’t want to use an existing function , I am just appliying my knowledge) word = input("Enter a string : ") def Ino_String(word,part): # if part is in word s will indicate the position where the starting position …

Total answers: 1

Looping through dictionary and updating values

Looping through dictionary and updating values Question: I would like to cycle through a list of questions and for each answer update the key-value pair in the corresponding position. So for the first iteration, it presents the first question in the list and updates the first key-value pair in a dictionary. Right now the below …

Total answers: 1

driver doesn't close after not finding an element, python

driver doesn't close after not finding an element, python Question: could you find an error in my code? I haven’t been able to get over this code for a week now, so I am forced to ask a community. I am trying to download 14.000 html pages into a folder (I use selenium), I have …

Total answers: 3

remove an element from a set and return the set

remove an element from a set and return the set Question: I need to iterate over a copy of a set that doesn’t contain a certain element. Until now I’m doing this: for element in myset: if element != myelement: … But I want something like this, in one line: for element in myset.copy().remove(myelement): … …

Total answers: 3