python-3.x

Python equivalent to `as` type assertion in TypeScript

Python equivalent to `as` type assertion in TypeScript Question: In TypeScript you can override type inferences with the as keyword const canvas = document.querySelector(‘canvas’) as HTMLCanvasElement; Are there similar techniques in Python3.x typing without involving runtime casting? I want to do something like the following: class SpecificDict(TypedDict): foo: str bar: str res = request(url).json() as …

Total answers: 2

Selenium – how to click on the button

Selenium – how to click on the button Question: I am looking for the way to click on the button which is located in html this way: <button class="MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButtonBase-root css-1rs4rtx" tabindex="0" type="button"> Zaloguj siÄ™<span class="MuiTouchRipple-root css-w0pj6f"></span></button> I tried few ways to find this with no success. from selenium import webdriver …

Total answers: 2

I don't understand why is this for loop so fast?

I don't understand why is this for loop so fast? Question: Today I was solving Project Euler’s problem #43 Problem and I ran into a somewhat interesting problem. I don’t understand why is my code so fast? from itertools import permutations def main(): numbers1_9 = [0,1,2,3,4,5,6,7,8,9] list_of_all_permutations = list(permutations(numbers1_9, 10)) length_of_my_list = len(list_of_all_permutations) number_of_times_it_ran=0 result …

Total answers: 1

program to find fibonacci sequence of a number

program to find fibonacci sequence of a number Question: how do i find the fibonacci sequence of a number . Here Is The code def fib(n): for i in range(n): b = 1 b+=i print(b) p = fib(9) the program just returns the normal sum. how to do this in the easy way Asked By: …

Total answers: 2

How do I separate measurement value and unit into their respective columns if they appear together in DataFrame?

How do I separate measurement value and unit into their respective columns if they appear together in DataFrame? Question: I have a DataFrame which contains measurements; e.g., weight, height, etc. However, sometimes the measurement column contains units together with values. Therefore, I would like to separate measurement values and units if they are together in …

Total answers: 2

Running another class in the same window using tkinter

Running another class in the same window using tkinter Question: I’m trying to build my first app using python and tkinter. I’m stuck where I can’t run the content from another class into the same first window. The first window is a login window, here is the full code of the class: import tkinter as …

Total answers: 1

Replace value in mutiple columns based on dictionary map

Replace value in mutiple columns based on dictionary map Question: I have a dataframe that looks similar to – df = DataFrame(data={‘ID’: [‘a’,’b’,’c’,’d’], ‘col1’:[1,2,3,4], ‘col2’:[5,6,7,8], ‘col3’:[9,10,11,12]}) I have a dictionary like this mapper = {‘a’:100,’d’:3} Where the key in the dictionary matches the ID in the dataframe, I want to be able to replace the …

Total answers: 3