[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] Regex for replacing certain string in python [closed]

You need regular expressions for this: import re s=”abc xyz.xyz(1, 2, 3) pqr” re.sub(r'[a-z]{3}\.{[a-z]{3}\([^)]*\)’, ‘NULL’, s) Explanation: [a-z]{3} stands for 3 small letters (lower case) \. escapes the dot, as it is special character [a-z]{3} again 3 small letters \( escapes the left parenthesis [^)]* any character but right parenthesis, 0 or more time \) … Read more

[Solved] Python sort list by algorithm [closed]

Data = [ ‘<td>1</td>’, ‘<td>2</td>’, ‘<td>3</td>’, ‘<td>4</td>’, ‘<td>A</td>’, ‘<td>B</td>’, ‘<td>C</td>’, ‘<td>D</td>’, ‘<td>I</td>’, ‘<td>II</td>’, ‘<td>III</td>’, ‘<td>IV</td>’, ] lists, result = [], [] for i in range(0, len(Data), 4): lists.append(Data[i:i+4]) for currentList in zip(*lists): result += list(currentList) print result Output [‘<td>1</td>’, ‘<td>A</td>’, ‘<td>I</td>’, ‘<td>2</td>’, ‘<td>B</td>’, ‘<td>II</td>’, ‘<td>3</td>’, ‘<td>C</td>’, ‘<td>III</td>’, ‘<td>4</td>’, ‘<td>D</td>’, ‘<td>IV</td>’] solved Python sort list by … Read more

[Solved] (‘syntax %(name,name,name)’, )? [closed]

That’s not an error. When you do sys.stderr, you’re printing the representation of it, which is <open file ‘<stderr>’, mode ‘w’ at blah>. I’m not familiar with the sys module, so I’m not exactly sure what you should be doing. Here’s a link to the documentation on it however. solved (‘syntax %(name,name,name)’,

[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] Python: How can I use a specific integer from a list?

You can use the integers by calling their position in the list. Here’s an example of adding, subtracting, and finding the sum of your list: example = [12, 3, 4] print(example[0] + example[1]) #15 (12 + 3) print(example[2] – example[1]) #1 (4 – 3) print(sum(example)) # 19 (12 + 3 + 4) solved Python: How … Read more

[Solved] date extraction through regex [closed]

Without regex: s = “20160204094836A” year = s[:4] day = s[4:6] month = s[6:8] print(year, day, month) With Regex: import re s = “20160204094836A” result = re.search(r”^(\d{4})(\d{2})(\d{2})”, s) year = int(result.group(1)) day = int(result.group(2)) month = int(result.group(3)) print(year, day, month) solved date extraction through regex [closed]

[Solved] When to use append?

You have a list for example [1, 2, 3] If you want to add another element use append: list = [1, 2, 3] list.append(4) solved When to use append?

[Solved] any() function in Python

any(list) returns a boolean value, based only on the contents of list. Both -1 and 1 are true values (they are not numeric 0), so any() returns True: >>> lst = [1, -1] >>> any(lst) True Boolean values in Python are a subclass of int, where True == 1 and False == 0, so True … Read more

[Solved] Two list count specific elements and aggregate on spefic rule [closed]

There are many possible solutions. In my opininion this is the easiest: import heapq list1 = [2,5,7] list2=[4,6,9] counter1=0 counter2=0 sum1=0 sum2=0 full_list = list1 + list2 three_largest = heapq.nlargest(3,full_list) for n in three_largest: if n in list1: list1.remove(n) counter1+=1 sum1+=n else: list2.remove(n) counter2+=1 sum2+=n print(counter1) print(counter2) print(sum1) print(sum2) Note that you made a mistake … Read more