[Solved] Find all numbers in a string in Python 3 [duplicate]

[ad_1] Using the regular expressions as suggested by AChampion, you can do the following. string = “44-23+44*4522″ import re result = re.findall(r’\d+’,string) The r” signifies raw text, the ‘\d’ find a decimal character and the + signifies 1 or more occurrences. If you expect floating points in your string that you don’t want to be … Read more

[Solved] verify continuous segments in list [closed]

[ad_1] What about creating a small function that turns the lists into strings and runs a regex against it, You could tidy this up, or I could if you approve this concept I’m not a regex, expert I’m sure there is another way to do this without using the AttribeError but this will work, someone … Read more

[Solved] Python Division Function [closed]

[ad_1] The divmod function does exactly what you want: >>> a, b = divmod(9,5) >>> a 1 >>> b 4 However, if you want to define your own function, this should work: def divide(n1, n2): quotient = n1 // n2 remainder = n1 % n2 return (quotient, remainder) The // operator represents integer division, and … Read more

[Solved] Tkinter Placing And Deleting A Label

[ad_1] In your code, the label is placed, and after 2 seconds it is destroyed. It is never actually shown in your window however as it is not updated. This is as when entering Tk’s mainloop, it updates the window in a loop, checking if changes have been made. In your case, you are preventing … Read more

[Solved] Making Bank account in Python 3

[ad_1] Consider saving all the details in a dictionary with the primary key as the name and pin & balance as secondary keys. Then, you can save it to a json file. import json accdict ={} accdict[‘Obi’] = {‘Name’:’Obi Ezeakachi’,’Pin’:1111,’Balance’: 5000} Continue for all the accounts. with open(‘accounts.json’,’w’) as f: f.write(json.dumps(accdict)) You can now manipulate … Read more

[Solved] can someone explain this function to me

[ad_1] def look_up(to_search,target): for (index , item) in enumerate(to_search): if item == target: break # break statement here will break flow of for loop else: return(-1) # when you write return statement in function function will not execute any line after it return(index) print(“This line never be printed”) # this line is below return statement … Read more

[Solved] how do I count unique words of text files in specific directory with Python? [closed]

[ad_1] textfile=open(‘somefile.txt’,’r’) text_list=[line.split(‘ ‘) for line in textfile] unique_words=[word for word in text_list if word not in unique_words] print(len(unique_words)) That’s the general gist of it [ad_2] solved how do I count unique words of text files in specific directory with Python? [closed]

[Solved] How to remove part of a data string? [closed]

[ad_1] It’s unclear what ResultSet is and its format from your question, however the following example code might be helpful: import csv csv_filename=”result_set.csv” ResultSet = {“(u’maxbotix_depth’, None)”: [{u’time’: u’2017-07-12T12:15:54.107488923Z’, u’value’: 7681}, {u’time’: u’2017-07-12T12:26:01.295268409Z’, u’value’: 7672}]} with open(csv_filename, mode=”wb”) as csv_file: writer = csv.writer(csv_file) for obj in ResultSet[“(u’maxbotix_depth’, None)”]: time, value = obj[u’time’], obj[u’value’] print(‘time: {}, … Read more

[Solved] Compare values under multiple conditions of one column in Python

[ad_1] Try: #Use pd.Categorical to ensure sorting if column is not lexicographical ordered. df[‘type’] = pd.Categorical(df[‘type’], ordered=True, categories=[‘s1′,’s2′,’s3’]) df[‘result’] = df.sort_values(‘type’).groupby(‘name’)[‘value’].diff(-1) df[‘result’] = df[‘result’].lt(0).mask(df[‘result’].isna(),”) df Output: index name type value result 0 1 A s1 20 False 1 2 A s2 10 2 3 B s1 18 True 3 4 B s2 32 False 4 … Read more