Skip to content

Python f string with folders

I’m trying to use regex to find a specific file name in a folder, however it seems like my regex is not working. Inside my folder the names of the excel files are Answer You are not testing your regex against anything. pattern.fullmatch will return a method object. You probably wanted to write That bein…

How do i get the min and max value of tuples

How do i get the code to return 2 (lowest of all) and 29 (the biggest one) Answer When searching for the min, you want to first take the min of each tuple and then take the min through those. You can achieve this with map which has the advantage of not having to create an extra list in the

How do I implement the datetime module into my code?

So how do I make the string a date? The error: Answer When you’re creating your object you have to enclose the value inside quotes: Just 21.12.1999 by itself isn’t a valid Python definition of anything. You can then use strptime of the datetime.datetime module to parse it into a datetime, and retr…

More pythonic way of creating within-class scatter matrix

I am looking for a better way of calculating the following I would prefer getting rid of the for loops using numpy. This is the within-class scatter matrix for fischers linear discriminant. Answer You can write as follows: This is because sum_i x_i x’_i = X’ X, where X is (N, 3) matrix and x_i = X…

‘event’ has no “key” attribute

** this is a part of a code ** ** error shows that: 38, in _cheak_events elif event.key == pygame.KEYDOWN: AttributeError: ‘Event’ object has no attribute ‘key’ Answer Replace all event.key with event.type