[Solved] Hours and time converting to a certain format [closed]

This can be done conveniently by using the appropriate representation for your fractional hours, namely a timedelta. If the input is of datatype string, convert to float first. Ex: from datetime import datetime, timedelta for td in [8.25, 17.75]: # add the duration as timedelta to an arbitrary date to get a time object: print((datetime(2020,1,1) … Read more

[Solved] Extract single words or phrases from list of strings which are not in base string

Update This version adds all already seen words to the exclude set: exclude = set(‘why kid is upset’.split()) list_of_strings = [‘why my kid is upset’, ‘why beautiful kid is upset’, ‘why my 15 years old kid is upset’, ‘why my kid is always upset’] res = [] for item in list_of_strings: words = item.split() res.append(‘ … Read more

[Solved] Python: How find the index in list by its part?

I’d do it this way: result = [] reader = [‘sdsd-sdds’, ‘asaad’, ‘deded – wdswd’, ‘123’ ] str_1 = ‘deded -‘ for x in reader: if str_1 in x: result.append(reader[reader.index(x) + 1]) print(result) If you want to stop after finding the first one you should use a break after finding a value: result = [] … Read more

[Solved] Need help understanding a type error

Replace last main() with main(game) and make this small changes, remember to read the python tutorials, good luck! import random import math game = int(input(“How many problems do you want?\n”)) num_1 = random.randint(1,10) num_2 = random.randint(1,10) def main(game): random.seed() count = 0 correct = 0 result = 0 #Here we initialized result to 0 while … Read more

[Solved] ValueError: shapes (4155,1445) and (4587,7) not aligned: 1445 (dim 1) != 4587 (dim 0)

Have a look at the sci-kit learn documentation for Multinomial NB. It clearly specifies the structure of the input data while trainig model.fit() must match the structure of the input data while testing or scoring model.predict(). This means that you cannot use the same model for different dataset. The only way this is possible is … Read more

[Solved] Compare one item of a dictionary to another item in a dictionary one by one [closed]

Assuming the keys (here, prompt) of both dictionaries are the same, or at least for every key in the answers dictionary, there is a matching response prompt, then you can count them like so count = 0 for prompt, response in responses.items(): if response == answers.get(prompt, None): count += 1 return count 1 solved Compare … Read more

[Solved] TypeError: DisplayMarketingMessage() takes no arguments how to fix it

you can try following implimentation from django.utils.deprecation import MiddlewareMixin class DisplayMarketing(MiddlewareMixin): def process_request(self, request): try: request.session[‘marketing_message’]=MarketingMessage.objects.all()[0].message except: request.session[‘marketing_message’]=False solved TypeError: DisplayMarketingMessage() takes no arguments how to fix it

[Solved] Convert pandas column with currency values like €118.5M or €60K to integers or floats [closed]

Damn, a quick google search finds: def convert_si_to_number(x): total_stars = 0 x = x.replace(‘€’, ”) if ‘k’ in x: if len(x) > 1: total_stars = float(x.replace(‘k’, ”)) * 1000 # convert k to a thousand elif ‘M’ in x: if len(x) > 1: total_stars = float(x.replace(‘M’, ”)) * 1000000 # convert M to a million … Read more

[Solved] How to write a python program that takes a number from the users and prints the divisors of that number and then print how many divisors were there? [closed]

How to write a python program that takes a number from the users and prints the divisors of that number and then print how many divisors were there? [closed] solved How to write a python program that takes a number from the users and prints the divisors of that number and then print how many … Read more