[Solved] Python regex not printing contents in new list

You are looping over individual characters, not over lines: >>> maxline=”i have a Prof.John and As Maria a bike” >>> for line in maxline: … print line … i h a v e # …. etc. These individual characters don’t match your expressions. Change maxline to be a list; perhaps by splitting it on newlines … Read more

[Solved] How to compare the attributes start with $ in 2 functions and display match or mismatch

import re caselines_index = [] cases = [] readlines = [] def read(in_file): global cases global caselines_index global readlines with open(in_file, ‘r’) as file: for line in file.readlines(): readlines.append(line.strip()) for line in readlines: case_search = re.search(“case\s\”.+?\”\:\s”, line) if case_search: caselines_index.append(readlines.index(line)) #print caselines_index caselines_index_iter = iter(caselines_index) int_line_index = int(next(caselines_index_iter)) int_next_index = int(next(caselines_index_iter)) while True: try: case_text=” … Read more

[Solved] Why this code gives me error? [closed]

Here you go an answer to the whole program: Rock-paper-scissors-lizard-Spock template import random The key idea of this program is to equate the strings “rock”, “paper”, “scissors”, “lizard”, “Spock” to numbers as follows: 0 – rock 1 – Spock 2 – paper 3 – lizard 4 – scissors helper functions def number_to_name(number): # fill in … Read more

[Solved] Number divided by 4 by python regex

You are misunderstanding what […] does. They are character classes; if 1 character in that class matches, the text matches: >>> import re >>> re.search(r'[32]’, ‘3’) <_sre.SRE_Match object; span=(0, 1), match=”3″> >>> re.search(r'[32]’, ‘2’) <_sre.SRE_Match object; span=(0, 1), match=”2″> Don’t use a character class when you only want to match literal text. The following would … Read more

[Solved] How to add 0’s to a floating point number?

Float doesn’t support precision configuration, only rounding and formating. You should use decimal instead: >>> from decimal import * >>> getcontext().prec = 2 >>> Decimal(1) / Decimal(7) Decimal(‘0.14′) Python decimal: https://docs.python.org/2/library/decimal.html 2 solved How to add 0’s to a floating point number?

[Solved] Pandas returning object type instead of values

I think you need aggregation by sum: df3 = df2.groupby(‘Destination Address’, as_index=False)[‘Aggregated Event Count’].sum() Sample: df2 = pd.DataFrame({‘Destination Address’:[‘a’,’a’,’a’, ‘b’], ‘Aggregated Event Count’:[1,2,3,4]}) print (df2) Aggregated Event Count Destination Address 0 1 a 1 2 a 2 3 a 3 4 b df3 = df2.groupby(‘Destination Address’, as_index=False)[‘Aggregated Event Count’].sum() print (df3) Destination Address Aggregated Event … Read more

[Solved] Tournament Program [closed]

The error you have comes up in your method of printing out the results: for i in range(len(teams)): print(team[i],team[i+1]) First of all, you have team instead of teams in the print statement, which is actually the string where you were storing user input, and should be ‘-1′ by the time you’re printing scores. You’re getting … Read more