[Solved] find certain string in string

You could try solving the problem by patter matching the input string by using regular expression. Basic example for your case: import re input_str = input().lower() pattern = re.compile(r’^h+e+l{2,}o+$’) if pattern.match(input_str): print(‘YES’) else: print(‘NO’) solved find certain string in string

[Solved] Calculate the average budget of all movies in the data set [closed]

Supposing movies is a normal Python List and that you would like to get the average cost in Dollars: movies = [ (“Titanic”, 20000000), (“Dracula”, 9000000), (“James Bond”, 4500000), (“Pirates of the Caribbean: On Stranger Tides”, 379000000), (“Avengers: Age of Ultron”, 365000000), (“Avengers: Endgame”, 356000000), (“Incredibles 2”, 200000000) ] totalCost = 0 totalMovies = 0 … Read more

[Solved] Code returns invalid syntax [closed]

Your return statements and indentation are messed up: def tag_count(string_list): count=0 for string in string_list: if string.endswith(‘>’) and string.startswith(‘<‘): count += 1 return count print (tag_count([“test”,”<item>”,”test”])) 1 solved Code returns invalid syntax [closed]

[Solved] Regex substring in python3

No need for regex here, you can just split the text on \n and : , i.e..: text = “””It sent a notice of delivery of goods: UserName1 Sent a notice of delivery of the goods: User is not found, UserName2 It sent a notice of receipt of the goods: UserName1 It sent a notice … Read more

[Solved] How to iterate over a dictionary and a list simultaneously? [closed]

You can use: maketrans–which allows creation of a translation table translate–applies translation table from maketrans to a string Code def encrypt(infile, outfile, translation): ”’ Encrypts by applying translation map to characters in file infile. ”’ # Create translation table table=””.maketrans(translation) # Apply table to all characters in input file # and write to new output … Read more

[Solved] how pass variables in api calll python?

You can use params in requests to use arguments in url import requests data = [“AAPL”, “SQ”, “PLTR”] data_str = “,”.join(data) url = “https://stocknewsapi.com/api/v1” payload = { “tickers”: data_str, “items”: 50, “date”: “last7days”, “token”: “myapikey”, } response = requests.get(url, params=payload) Eventually you can use string formatting with {} and .format(data_str) data_str = “,”.join(data) url = … Read more

[Solved] select variable from column in pandas

This will give you filtered dataframe with all the columns where Region is Europe and Purchased Bike is Yes agestock = pd.DataFrame({ ‘Region’: {0: ‘Europe’, 1: ‘Europe’, 2: ‘Europe’, 3: ‘APAC’, 4: ‘US’}, ‘Age’: {0: 36, 1: 43, 2: 48, 3: 33, 4: 43}, ‘Purchased Bike’: {0: ‘Yes’, 1: ‘Yes’, 2: ‘Yes’, 3: ‘No’, 4: … Read more

[Solved] Efficient loading of Pygamescreens to 2D-lists

You can almost triple the speed by using pygame.surfarray. But I don’t thing you actually want to have a list of the pixels. Please post a new question with you underling problem, as @hop suggested. def load(screen): return pygame.surfarray.pixels2d(screen).tolist() solved Efficient loading of Pygamescreens to 2D-lists

[Solved] How can I extract two most expensive items from a dictionary using standard library? [closed]

You could sort the list of dictionaries by the price reversed and then use slicing notation to return the top results. from operator import itemgetter top = 3 data = [{“name”: “bread”, “price”: 100}, {“name”: “wine”, “price”: 138}, {“name”: “meat”, “price”: 15}, {“name”: “water”, “price”: 1}, {“name”: “fish”, “price”: 10}] print(sorted(data, key=itemgetter(‘price’), reverse=True)[:top]) Output: [{‘name’: … Read more