string-length

How to print the longest sentence from a column in a csv file

How to print the longest sentence from a column in a csv file Question: I am very new to python and am really struggling with this problem. I have a csv file with different columns, labeled "height" "weight" "full_name" etc. I’m trying to create a function that will look through the full_name column and return …

Total answers: 2

Learning Python – len() returns 2n+2

Learning Python – len() returns 2n+2 Question: I’m sorry if this is a duplicate post but search seemed to yield no useful results…or maybe I’m such a noob that I’m not understanding what is being said in the answers. I wrote this small code for practice (following "learning Python the hard way"). I tried to …

Total answers: 3

How to print each element of a list until a certain length Python

How to print each element of a list until a certain length Python Question: How to print each element of my list to a defined length (5), so for example: myList = ["abcdefgh", "ijklmnop"] The output I’m looking for is: abcde ijklm I’ve tried this (printing dates from an excel sheet): i = 2 x …

Total answers: 1

Print the words of the string and their length along the same time

Print the words of the string and their length along the same time Question: Hoping you all to be fit and fine…. I have been trying since a while to get the result of one of the codes that I have written….but unable to get the desired result…Would be more than happy if you could …

Total answers: 4

Calculate average the letter length of a phrase with one function

Calculate average the letter length of a phrase with one function Question: I did this programming to calculate the average letters of a phrase. Do you think this program is responsible for all texts? And do you have a better offer? Thanks # calculate average word length of phrase print("This program will calculate average word …

Total answers: 1

Create dictionary with length of string as key and string as value

Create dictionary with length of string as key and string as value Question: I have a list with random strings, as the one below: strings = [“zone”, “abigail”, “theta”, “form”, “libe”, “zas”] What I want is a dictionary with len of those strings (non unique, linear as they are in the list) as keys, and …

Total answers: 3

Length of string in Jinja/Flask

Length of string in Jinja/Flask Question: Jinja unfortunately does not support executing arbitrary Python code, such as {% if len(some_var)>1 %} … {% endif %} My current workaround is to use the deprecated, ugly, double-underscore method: {% if some_var.__len__()>1 %} … {% endif %} Although this works, I’m afraid that some future implementation of strings …

Total answers: 1

How to get the size of a string in Python?

How to get the size of a string in Python? Question: For example, I get a string: str = “please answer my question” I want to write it to a file. But I need to know the size of the string before writing the string to the file. What function can I use to calculate …

Total answers: 7

Why does Python code use len() function instead of a length method?

Why does Python code use len() function instead of a length method? Question: I know that python has a len() function that is used to determine the size of a string, but I was wondering why it’s not a method of the string object? Asked By: fuentesjr || Source Answers: met% python -c ‘import this’ …

Total answers: 9