All Questions
34 questions
0
votes
1
answer
443
views
Is collections.deque() the best implementation of constant length list in Python?
I want to limit the length of the list in python, when len(list) > limit, the first item will be removed, collections.deque() can achieve it, however, will it be slower than:
list_A = [2,4,6,8,11]
...
0
votes
1
answer
86
views
Getting a maximum of 2 values of a column based on having same values in the first field using pandas dataframe
I have three separate columns: Link_Id, NEW, Length in a data frame.
I want to group similar Link_Ids together and then collect their Length values, out of those having the maximum Length value I want ...
3
votes
1
answer
395
views
Divide too long text in similar chunks considering punctuation
I have a list of strings that have to be not more than X characters. Each string can contain many sentences (separated by punctuation like dots). I need to separate longer sentences than X characters ...
0
votes
0
answers
852
views
PIL text exceeds desired length
Today I have a question in relation of some of the PIL modules, specifically: the Image, ImageDraw, ImageFont. My problem starts when trying to write on an image with the ImageDraw module:
The text ...
0
votes
0
answers
1k
views
Executing string in Python exceeding the max string length
I want to execute my code saved in the variable texto that exceeds the max string length (8000) that exec() accepts.
I found this post where it is said that using + the problem can be solved by ...
1
vote
1
answer
298
views
Better way to filter two list of lists by checking length of the inner lists
Given two list of lists, the goal is to filter out the list based on the length of the inner list.
The length criteria is set by the user, i.e.
>>> x = [[1,2,3], [1,2,3,4,5,6], [1,2,3,4,5], [...
-1
votes
3
answers
6k
views
How to use range() with while loop?
I need to create an empty list
Ask the user for any input 5 times
Only add the input to the list if it does NOT already exist
I keep getting into an infinity loop instead of only 5 times.
That's my ...
1
vote
0
answers
112
views
empty column: object is 'float' and has no len()
Bu running this code I'm trying to filter the files that it reads, one of those filters is:
if the file has 'SOURCE' column then: if the lambda len().max() of
'SOURCE' column is > 0, we can ...
2
votes
1
answer
634
views
max_length doesn't fix the question-answering model
My Question:
How to make my 'question-answering' model run, given a big (>512b) .txt file?
Context:
I am creating a question answering model with the word embedding model BERT from google. The ...
0
votes
1
answer
241
views
string formatting not working as expected
I am trying to format strings to print in a fashion that fits the following:
Payday 1000.00
groceries -50.00
dinner out wit -175.00
bacon, eggs, & -50.00
total: 725
And for ...
1
vote
1
answer
1k
views
Django: ModelMultipleChoiceField is applying underlying model's max_length validator to total length of selected results
I'm using a ModelMultipleChoiceField to allow users to select certain model objects to delete. It works fine when a single object is selected, but when multiple objects are selected then a validation ...
1
vote
1
answer
3k
views
Python Pandas Truncate a column to a specific length without cutting the last word
I try to reduce the length of a column to 50 and I use this lambda fct:
df['col_1'] = df['col_1'].apply(lambda x: x[:50])
It is working just fine excepting the fact that its cutting the last word, I ...
-2
votes
7
answers
1k
views
How can i delete elements in a list with remove order? [duplicate]
I have a list like this lst = [1,3,5] and a major list like lost =['the' , 'cat' , 'thinks' , 'you' , 'are' , 'crazy' ]
I want to delete elements in second list based on indexes in the first one . ...
6
votes
3
answers
2k
views
How to validate automatically String/Unicode columns maximum length when specified on declaration?
SQLAlchemy allows to specify a length when declaring String columns:
foo = Column(String(10))
as in SQL:
foo VARCHAR(10)
I know this length value is used by some DBMS to allocate memory when ...
1
vote
1
answer
141
views
Django max_length of another model attribute
I want to have the integer value of one model attribute be the max_length of another model attribute like mentioned below "capacity = models.IntegerField(max_length=Concerthall.capacity)".
class ...
1
vote
2
answers
200
views
Limiting size of an empty widget
I have been surfing the web for answers that don't use the 'class' function but have not been very successful. What I've got is 3 entry boxes, for example, and I am trying to use this function (...
4
votes
2
answers
3k
views
How to reduce max_length of CharField in Django when data already exists in db
I have a CharField on a Django (1.9) model:
alias = models.CharField(max_length=50)
The app is being used and already has data, and there are objects using all 50 characters already. What is the ...
1
vote
2
answers
1k
views
Minimal max_length of a Django CharField to store the output of the sign method of a Signer object (django.core.signing)
I have to sign a value, in my case emails, and I have to store the signed value in a Django CharField.
I am using the Signer.sign method of the django.core.signing module.
Since I would like to insert ...
1
vote
2
answers
80
views
Conditional statment regarding various regex and length of a list in python
I have following list :
['E12.2', 'E16.1', 'E15.1']
['E10.1', 'I11.2', 'I10.1_27353757']
['E16.1', 'E18.1', 'E17.3']
['E1.8', 'I12.1_111682336', 'I12.1_111682195']
['E55.1', 'E57.1', 'E56.1'...
4
votes
3
answers
5k
views
How to add a specific number of characters to the end of string in Pandas?
I am using the Pandas library within Python and I am trying to increase the length of a column with text in it to all be the same length. I am trying to do this by adding a specific character (this ...
1
vote
3
answers
2k
views
How to select words of equal max length from a text document
I am trying to write a program to read a text document and output the longest word in the document. If there are multiple longest words (i.e., all of equal length) then I need to output them all in ...
0
votes
1
answer
1k
views
Bypassing size limitation on a subprocess command
I need your help to solve my problem. I want to launch a powershell command using subprocess. However the command used will be very long, so it will be bigger than the size of the buffer. I have done ...
0
votes
2
answers
259
views
digits in a string fit in between max and min
So I am trying to get my string to be verified between 1000 to 9999 and when I try to run this, it comes back saying it is unverified. Curious on how to fix this problem so that it can actually read ...
1
vote
4
answers
4k
views
How to use recursion to calculate the max length of a nested list?
Here is the code that counts the maximum length in a nested list.
def max_length(obj):
"""
Return the maximum length of obj or any of its sublists, if obj is a list.
otherwise return 0.
...
0
votes
4
answers
2k
views
Pythonic way to set a maximum length parameter
What is the pythonic way to set a maximum length paramter?
Let's say I want to restrict a list of strings to a certain maximum size:
>>> x = ['foo', 'bar', 'a', 'rushmoreorless', '...
12
votes
1
answer
9k
views
Python regex pattern max length in re.compile?
I try to compile a big pattern with re.compile in Python 3.
The pattern I try to compile is composed of 500 small words (I want to remove them from a text). The problem is that it stops the pattern ...
3
votes
3
answers
3k
views
How to override max length of username in Django by creating a custom model
I have a problem. I'm using Django 1.7, and have already made a custom user model, that inherits Django's abstract user like this:
class CustomUser(AbstractUser, BaseModel):
Now they say in here ...
1
vote
1
answer
1k
views
Django use Widget to Override ModelForm Attributes
I have a tags CharField with a maxlength of 300, but I need to reserve 100 characters of that for default inputs, but I want users to be able to set the remaining 200 characters via an input text box. ...
14
votes
1
answer
24k
views
Creating an empty deque in Python with a max length?
I'm looking at the documentation for a Python deque, and it looks like the constructor is deque([iterable[, maxlen]]). Is there no way to make an empty deque (that is, without specifying the iterable) ...
0
votes
3
answers
3k
views
Making sure length of matrix row is all the same (python3)
so I have this python 3 code to input a matrix:
matrix = []
lop=True
while lop:
line = input()
if not line:
lop=False
if matrix != []:
if len(line.split()) != len(matrix[-...
8
votes
3
answers
3k
views
How to find minimum, maximum length strings generated given a regular expression? [closed]
How to find minimum and maximum length given a regular expression ?
For example
[1-9]?[0-9]
This regular expression can generate a minimum 1 (0 or 1 0r 2.... or 9) and a maximum of string length 2 ...
1
vote
5
answers
4k
views
Return len of the longest word in a list [duplicate]
Hi, I'm trying to make an python program that will return the length of the longest word in a list but it does not work so well for me.
here is the code:
def find_longest_word():
list1 = ['a','aa'...
22
votes
5
answers
59k
views
How to set a max length for a python list/set?
In c/c++, we could have:
maxnum = 10;
double xlist[maxnum];
How to set a maximum length for a python list/set?
0
votes
1
answer
2k
views
Setting max_length of a form field using a parameter in Django
I have a parameter that I am passing in to the form. It is a dictionary to configure the form.
How can I set the max_length of a field using a value from the dictionary?
class StepTwoForm(forms....