Skip to content
Advertisement

Tag: string

Append to a string with characters in a while loop python

I’m running into a problem which I cannot solve online- all answers I’ve found only allow the appending to happen once since it just keeps repeating the same action. For context: If a string isn’t 128 lines long- I want to pad it out to reach 128. All padding should add 00 then move to the next line. For example:

How do I print name of array in Python?

I have few arrays, in my code. I wanna be able to change, which I am using in one place, and to be able to print name of it only changing one line (definition). Example: Now I want to have in print being to able call XYZ array not my_array. So I don’t have to change it twice, but It

how to analysis String contain multiple list in python

I have a string as follows I use json.load with ast.literal_eval neither works Is there any function that can quickly and perfectly parse this string? hope through like output: C Answer The string does not represent a valid Python construct. Therefore, neither eval nor ast.literal_eval will be able to parse it. However, it appears that all you need to do

Find the average length of all words in a sentence

Given a string consisting of words separated by spaces (one or more). Find the average length of all words. Average word length = total number of characters in words (excluding spaces) divided by the number of words. My attempt: But input is incorrect, can you help me? Answer When you’re stuck, one nice trick is to use very verbose variable

Which way is better to concatenate strings in python? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 7 months ago. Improve this question Which way is better in this case and why? emails.append(user + “@” + domain) emails.append(“{}@{}”.format(user, domain)) Answer In my honest opinion,

How to test for substrings in the list

I need to check if a string is in the list my_list. When I run ‘word2’ in my_list, it returns False instead of True. How can I test for substrings in the list? Answer You have to check whether your string is part of each list element. Something like this:

Python Regex groups causing index errors

So, my interpereter is complaining about IndexError: Replacement index 1 out of range for positional args tuple when calling re.group(#) or re.groups() under specific circumstances. It is meant to return a phone number, such as +1 (555) 555-5555 Here is the regex used, as it is declared elsewhere: Here is the code causing the issues: Full Traceback: Answer You have

How to add space on a complex string?

I have this string that act’s like a progress bar And looks like this : Please could you explain me how to add a single space like ” ” in the red arrow? Like end of the bar, space and then the 100 % percentage, because in my image they are too closed, probably it’s an easy task but i

Advertisement