if-statement

Why does shorthand if assignment to list not work?

Why does shorthand if assignment to list not work? Question: Trying to use the code given below I get the error: row[0] = "M" if row[0] == "male" else row[0] = "F" ^^^^^^ SyntaxError: cannot assign to subscript here. Maybe you meant ‘==’ instead of ‘=’? rows = [] for row in csvreader: row[0] = …

Total answers: 1

I Have one for condition, and can't do if statement to count cell condition

I Have one for condition, and can't do if statement to count cell condition Question: I’m trying to do this condition to count how many times (cells) have values less than 300 seconds (5 minutes) but it returns me an error, the condition is about a DF below, that I pull from my csv: df …

Total answers: 1

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

In if-elif-else, the if statement is TRUE yet the else statement is getting executed

In if-elif-else, the if statement is TRUE yet the else statement is getting executed Question: string = "aabbcc" count = 3 while True: if string[0] == ‘a’: string = string[2:] elif string[-1] == ‘b’: string = string[:2] else: count += 1 break print(string) print(count) The output for the program is ‘bbcc’ and 4. But I …

Total answers: 2

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

Changing data types twice in one conditional statement (Python)

Changing data types twice in one conditional statement (Python) Question: Pretty basic question, but I am trying to write a simple while loop in which I first need an input as int. But in order to break out of said loop, I want to be able to write ‘quit’ which is a string. How do …

Total answers: 2

Python – Assesing each line in a file against an IF

Python – Assesing each line in a file against an IF Question: The below works for a single ip or fqdn, but for a list of assets its failing and assigning them all as FQDNs. #!/usr/bin/env python import argparse import ipaddress import re def parse_args(): # Assess arguments parser = argparse.ArgumentParser(description=’do some sh*t’) parser.add_argument(‘-T’, required=True, …

Total answers: 1

Pandas itertuples – fill in a matrix with a value based on an event

Pandas itertuples – fill in a matrix with a value based on an event Question: I am trying to create a matrix in which I fill in the date of the first occurence of an event per row after the specified stamp date in the said row. Sample dataframe: id = [1,1,1,1,1,2,2,2,2,3,3,3,3,4,5,6,7,7,7,8,8,8,9,9,9,10,10,10] fact = ["IC", …

Total answers: 1