loops

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

Why are for-loops much slower than broadcasting

Why are for-loops much slower than broadcasting Question: Comparing two chunks of code for a simple matrix operation, the one with a nested for loop is much slower. I wonder: what is the underlying reason for this? This loop tuns for 2.5 seconds: m = np.zeros((800,8000)) for i in range(0,800): for j in range(0,8000): m[i,j] …

Total answers: 1

Iterate through a string and append static values to a list for every occurrence of substring (Python)

Iterate through a string and append static values to a list for every occurrence of substring (Python) Question: I’m currently stuck on some basic Python. I currently have a very long html string that looks something like this: <relative-time class="no-wrap" datetime="2023-03-07T02:38:29Z" title="Mar 6, 2023, 7:38 PM MST">Mar 6, 2023</relative-time>, <relative-time data-view-component="true" datetime="2023-03-06T10:25:38-07:00 I want to …

Total answers: 1

How to get only a single output of the result in python program?

How to get only a single output of the result in python program? Question: I was writing a code in python to identify prime number. Here is the code n=int(input("Enter any integer")) for i in range(2,n,1): if n%i==0: print(n, " is not a prime number") break else: print("Prime number") But the problem is that I …

Total answers: 3

Finding minimum iterative

Finding minimum iterative Question: sales_data = { ‘order_number’: [1001, 1002, 1003, 1004, 1005], ‘order_date’: [‘2022-02-01’, ‘2022-02-03’, ‘2022-02-07’, ‘2022-02-10’, ‘2022-02-14’] } sales_data = pd.DataFrame(sales_data) capacity_data = { ‘date’: pd.date_range(start=’2022-02-01′, end=’2022-02-28′, freq=’D’), ‘capacity’: [0, 0, 0, 1, 1, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, …

Total answers: 2