[Solved] Syntax error in python 3 when I’m trying to convert a date but no luck on trying to solve it [duplicate]

Python 3 Code: def main(): dateStr = input(“Enter a date (mm/dd/yyyy): “) monthStr, dayStr, yearStr = dateStr.split(“https://stackoverflow.com/”) months = [“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”] monthStr = months[int(monthStr)-1] print (‘Converted Date: ‘ + ‘ ‘.join([str(dayStr), monthStr, str(yearStr)])) main() Python 2 Code: Use raw_input: def main(): dateStr = raw_input(“Enter a … Read more

[Solved] Signal Correlation in python [closed]

You can use scipy.signal.resample for that. # Generate a signal with 100 data point import numpy as np t = np.linspace(0, 5, 100) x = np.sin(t) # Downsample it by a factor of 4 from scipy import signal x_resampled = signal.resample(x, 25) # Plot from matplotlib import pyplot as plt plt.figure(figsize=(5, 4)) plt.plot(t, x, label=”Original … Read more

[Solved] count prime number in a list

Here is my fix of your code. def count_primes_in_list(numbers): primes = [] for num in numbers: if num == 2: primes.append(num) else: is_prime = True for i in range(2, num): if num % i == 0: is_prime = False break if is_prime: print (num) primes.append(num) return len(primes) z = [4, 5, 6, 7, 8, 9, … Read more

[Solved] How to read, edit, merge and save all csv files from one folder?

This should be fairly easy with something like the csv library, if you don’t want to get into learning dataframes. import os import csv new_data = [] for filename in os.listdir(‘./csv_dir’): if filename.endswith(‘.csv’): with open(‘./csv_dir/’ + filename, mode=”r”) as curr_file: reader = csv.reader(curr_file, delimiter=”,”) for row in reader: new_data.append(row[2]) # Or whichever column you need … Read more

[Solved] In Python 3.6, How to display which lines a word occurs in a text file?

This program should behave as you wanted: with open(“test.txt”,’r+’) as f: # Read the file lines=f.readlines() # Gets the word word=input(“Enter the word:”) print(word+” occured on line(s):”,end=’ ‘) # Puts a flag to see if the word occurs or not flag=False for i in range(0,len(lines)): # Creates a list of words which occured on the … Read more

[Solved] Print elements of list horizontally [closed]

Here’s a silly one-liner version: def print_table(seq, width=3): print(‘\n’.join([”.join( [(str(u[-i]) if len(u) >= i else ”).rjust(width) for u in seq]) for i in range(max(len(u) for u in seq), 0, -1)])) And here’s the same algorithm in a somewhat more readable form: def get_cell(u, i): return str(u[-i]) if len(u) >= i else ” def print_table(seq, width=3): … Read more

[Solved] python self is acting up

Normally, when you create an instance of a class draw, the initialization routine draw.__init__ is automatically called for you, and the self argument is added implicitly, so you don’t specify it explicitly. Here’s the normal case: d = draw( canvas, 20, 40, … ) …and indeed that’s just what you seem to have assumed. Your … Read more

[Solved] Sort a list of integers basis the remainder they leave when divided by 5 in an ascending order? [closed]

Python’s sort() has the optional argument key. You can use a lambda function as the key like so: numbers = [1, 9, 35, 12, 13, 21, 10] numbers.sort(key=lambda i: i % 5) print(numbers) A quick explanation of what’s going on here: A lambda function is a function that is defined in-line and isn’t named. lambda … Read more