I would think that the default color cycle would be (some variants of) [‘blue’, ‘red’, ‘green’, ‘purple’, ‘orange’] like in the plot below: Plot 1: Code 1: At least that seems to be the order of the cycle since omitting Oceania from the continents wi…
What’s wrong for the error of Time Limit Exceeded on leetcode 53. Maximum Subarray?
My code is below for leetcode 53.Maximum Subarray, but one test case is not passed. How can I fix my current code to prevent Time Limit Exceeded? Answer You are getting TLE because your solution’s runtime is O(n^2). The time complexity can be reduced by two ways. Either you need to use divide and conque…
How to avoid zipfile error with python-pptx saving files
I am using the python-pptx package to create a number of .pptx files from a series of dataframes. All works well with adding slides and such until it comes time to call prs.save() where “prs” is the Presentation. Doing so leads to a zipfile error re: open handles needing to be closed. I have done …
Removing SEP token in Bert for text classification
Given a sentiment classification dataset, I want to fine-tune Bert. As you know that BERT created to predict the next sentence given the current sentence. Thus, to make the network aware of this, they inserted a [CLS] token in the beginning of the first sentence then they add [SEP] token to separate the first…
Plotly-Express: How to fix the color mapping when setting color by column name
I am using plotly express for a scatter plot. The color of the markers is defined by a variable of my dataframe, as in the example below. When I add another instance of this variable, the color mapping changes (First, ‘virginica’, is red, then green). How can I keep the mapping of the colors when …
Seaborn histogram makes columns white
In what cases Seaborn makes histogram columns white? I use it Seaborn in Jupyter notebook: Then I plot histogram using this function: As a result in some cases I have histograms with all blue columns or some blue and some white or only white columns. Please, see attached pictures. How to make Seaborn always d…
No module named ‘folium’ after installing via pip
Basically after I have already installed folium with pip (pip install folium) previously the code worked, but suddenly I got this error. Here is my code: Answer 2 possibilities come to my mind: the first one, cited by Paul, is that you installed it with pip (for Python 2) and you try using it with Python 3 (s…
Differentiate class and object in Python type hints
Django’s post_save signal sends a model class argument – sender – along with the actual instance being saved – instance. Is there a way to differentiate between the two in type hints? Example We have a model User and would like to create a post_save signal: As you can see, I have given both sender and i…
Python regular expression SyntaxError: unexpected character after line continuation character
I must have totally messed up my regular expression. I’m trying to find the ID and value in the following str (and eventually will need to find description and it’s value too): But for some reason, I get the above error message. This is my code: I tested in https://pythex.org/ and the regular expr…
How should I use this hexadecimal data to send ble command to device?
I have a chinese manual for this ble relay board which seems to state that in order to activate relay #1 the command sent is: C5 04 as a prefix 12345678 for the password part AA as a suffix How do I send this from a python script? I used this in the past: for a different board. I know