Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
1 answer
50 views

Why am I getting an empty string if I use positive start index and negative stop and step index values?

I am trying to run this code snippet: test="test" print(test[3:-1:-1]) For the slicing, the start index should start from 3 which is inclusive and stop index should be -1 exclusive which ...
kiran kumar's user avatar
-4 votes
0 answers
28 views

Syntax help: why is my code ignoring my last elif statement? [duplicate]

I am attempting to create a random generator for cat coat patterns and colors. First, my generator selects a coat pattern. It could be a tabby, a calico etc. Then from there, it will select the ...
Wrenly's user avatar
  • 1
1 vote
3 answers
66 views

Find str.contains in two large Pandas DataFrames

I have a large pandas DataFrames like below. import pandas as pd import numpy as np df = pd.DataFrame( [ ("1", "Dixon Street", "Auckland"), ("2&...
Totura's user avatar
  • 29
0 votes
0 answers
34 views

__str__ in python not respecting escape keys [duplicate]

So I'm learning about object oriented programming and the __str__ method, and I'm finding that when adding things to a list the formatting of the item is different to when I simply print a particular ...
The grumpy baker's user avatar
-1 votes
1 answer
41 views

How to include variables in a multiple line string in Python? [duplicate]

For example, I have the following: first_count = 5000 query = ''' { students(first: first_count) { id firstName college { id name location ...
winterlyrock's user avatar
-1 votes
2 answers
101 views

Why does this not print hello at the end but instead the letters are all scrambled

Im tying to create a effect that make the string "hello" gradually appear: import time text = "hello" alphebet = [ "a", "b", "c", "d", &...
Jakob Brooks's user avatar
-1 votes
1 answer
30 views

splitting a string into workable lists (Python)

I want to be able to turn a user input string into a string list and then modify that list as needed.For example sake I will be useing: (a+b)(b+a). where the final result is list[0]=a+b and list[1]=b+...
George Volz's user avatar
-4 votes
1 answer
54 views

Regex consonant mismatch [closed]

I am trying to use Python and regex to search for words that look in certain defined ways. Can anyone tell me why the following code returns the word "choosy" as part of the output? I ...
Mikkel Marqvorsen's user avatar
0 votes
0 answers
22 views

How to perform something like 'ordered_choice' replacement which returns a single text string when called similar to performance of 'random.choice'?

This question and code attempt is based mainly on the question asked here: random.choice() equivalent in order and here: Python read first and second lines then second lines and third lines The ideal ...
Ron's user avatar
  • 1
1 vote
1 answer
61 views

Replace characters before a number to a new character after the number python

I have some strings look like: *.rem.1.gz and *.rem.2.gz And I want to replace it into *.1.trim.gz and *.2.trim.gz The number 1 and number two files are paired with each other, which I want to create ...
Pluto Liu's user avatar
0 votes
1 answer
60 views

Unicode strings in a purely python3 codebase - are these useless? [duplicate]

In the codebase that I'm working on, there seems to be remnants of python2 because a lot of the strings are prefixed with u. From researching, it looks like this denotes a unicode string, but in ...
NFeruch - FreePalestine's user avatar
0 votes
1 answer
46 views

Find a Substring in String with Boardtools is not working if the string contains special chars

Today I got frustrated. I'm implementing a very simple logic with substring finding; it turned out to be a more complex situation. Let's consider this small python code: word_one, word_two = ['(/ %$ss%...
Allan Karlson's user avatar
-1 votes
2 answers
41 views

Why does the str() not work on filter objects?

besthand = "AAAAJ" besthand = str(filter("J".__ne__, besthand)) why is the type of besthand still a filter object? I've seen that you can use besthand = "".join(besthand)...
venom's user avatar
  • 3
-2 votes
3 answers
148 views

How can we use Python to extract Arabic words from a string of text? [duplicate]

Suppose that we have a string of text that contains a mixture of English words and Arabic words. Our goal is to extract the Arabic words and omit or delete all English words. Input: The initial Baa’ “...
Toothpick Anemone's user avatar
1 vote
1 answer
85 views

Python 3 process non-printable characters in a unicode string [duplicate]

I'm reading text that contains non-printable characters such as backspaces from a file example.log. If I'm reading the content of the file in a terminal running cat example.log, I obtain a well ...
m.raynal's user avatar
  • 3,113
0 votes
3 answers
291 views

Multiple substrings in string python within variable check [duplicate]

I have the following code: check = "red" in string_to_explore How can I replicate it for multiple substrings? I tried with: check = "red|blue" in string_to_explore but doesn't ...
iraciv94's user avatar
  • 840
-2 votes
2 answers
101 views

How to get a single slash in the string?

Image: I have the following string: 'To reach the peak \\U0001fa77' It is clear that the last part is the emoji symbol, but it has to slashes before it, so when I print the string, I get 'To reach ...
Anna Denisova's user avatar
-2 votes
1 answer
46 views

When I tried to count the string of translated language (tamil) in Python, it didn't give me the correct count why?

code I tried to count the string for the name 'KUMAR' with length function, output came 5 it is correct. But when I tried to count the same name in a different language(Tamil) the output I expected ...
Manoj's user avatar
  • 1
0 votes
0 answers
45 views

Regular expression matching variable at end of string

I have some histograms in a .root file which are called "Name/NameEvent1Ch0", "Name/NameEvent1Ch1"... "Name/NameEvent1Ch31" ... "Name/NameEvent2Ch0"... "...
Beth Long's user avatar
  • 391
0 votes
0 answers
41 views

Single quotes being swapped for double quotes upon replace

I have a pandas DataFrame that looks like this orig_id modified_id original_term modified_term 1929 3668340 3578283 Advocate for clients'' needs. Advocate for ...
Matt Cremeens's user avatar
0 votes
0 answers
38 views

Formatting multiplication tables in python; not how to, just some explanation

I'm meant to make a multiplication table in Python using nested loops. I had trouble formatting it to make a table and looked for answers online. I came across a solution: uplim=int(input("What ...
lillian's user avatar
  • 11
0 votes
3 answers
64 views

Print separate word string horizontally

I'm beginner just start learning python and this is really confusing me because i want to test practicing using string. The output should be like above. The spacing between two columns is one tab.
Rizard's user avatar
  • 11
-1 votes
2 answers
39 views

Looping through string - Adding and skipping characters

I have the below code (which is wrong) and i would like to count the number of times the word "car" appears. So the output here would be 2. word="cccccccaaaaaaaaaaarrrrrccar" count=...
DMach's user avatar
  • 87
1 vote
1 answer
80 views

Get a list of replacement fields from a Python string

I have a string like this: my_str = '{one}, {two}, {three}' print(my_str.format(one=1, two=2, three=3)) #1, 2, 3 I would like a list of replacement fields in my string: get_replacement_fields(my_str) ...
non87's user avatar
  • 135
-1 votes
1 answer
49 views

Index out of range error on Leetcode problem no 17

can anyone tell me why i am getting an IndexError in the following code. It doesn't make any sense to me. class Solution(object): def letterCombinations(self, digits): matchnums={ &...
Anurima Sengupta's user avatar
0 votes
1 answer
42 views

Turning infix notation to prefix notation has problems in formatting (Python)

I'm trying to create a program that turns infix notation to prefix notation, regardless of what kind of number the user inputs(like it could be a variable like A B or am integer like 3 34 23) here's ...
PCG Doris's user avatar
0 votes
2 answers
102 views

Convert tree-like structure formatted as a string using indentations to a list of paths

I have a string like this: Given_String = """\ Shoes Fruits Red Apple Cherry ! Yellow Banana Grapes Small Big ! ! ! """ I want to convert it into a ...
Abhishek Chakraborty's user avatar
0 votes
1 answer
50 views

Why python allocate memory to string is different strategy?

String type uses Unicode representation. Unicode string can take up to 4 bytes per character depending on the encoding. I have know python use three kinds of internal representations for Unicode ...
krupesh Patel's user avatar
1 vote
1 answer
82 views

Replacing html tags around some text, with plotly/dash html components

I have an html file, the content is a table such as: <tr> <td> <p>Item 1</p> </td> <td> <p>Definition for Item ...
dpppstl's user avatar
  • 31
0 votes
1 answer
43 views

Convert String format to another format in Python

I extract a string a python file, the string is like this. string = "'Interest Rate <b>%.2f</b> of <b>%.2f</b> can not change to <b>%s</b> of new loan product &...
Houy Narun's user avatar
  • 1,715
1 vote
4 answers
120 views

Python - Removing special characters and adding numbers from String

I have the below code. There is a string with special characters and numbers. I try to remove the special characters and calculate the sum of the numbers in the string. I get error when i try to ...
DMach's user avatar
  • 87
0 votes
1 answer
39 views

Conversion of hexadecimal value represented as string into int in column in dataframe

I am working on a dataset where two of its attributes sport and dport have hexadecimal values such as 'Ox0303' and 'Ox5000' along with integer values. The datatype of these attributes is object type. ...
Priyanka Goel's user avatar
0 votes
2 answers
154 views

TypeError: can't concat str to bytes. It does not look any byte object around. python3

"TypeError: can't concat str to bytes" pops out at read(1) statement in following code. def __init__(self, infile): self.infile = infile while self.infile.read(1) != 'T': ...
jovian's user avatar
  • 3
-2 votes
2 answers
72 views

How to split a string into list of combinations

Given a string like /root/2/1/2, how do we construct the following list: ['/root/2/1/2', 'root/2/1', 'root/2', '/root']
Chetan Bhopal's user avatar
1 vote
1 answer
66 views

How do I check if one column value contains another column value and vice versa - Pandas

I'm working with string columns on a pandas dataframe and would like to check if I can check if one of 2 columns contains the string in the match column (& check both ways) Column1 | Column2 ...
Hari Shreyas's user avatar
0 votes
2 answers
99 views

How can I make user entries case-insensitive in Python 3? [duplicate]

I am following FreeCodeCamp's Python tutorial. I would like to know how I can make user entries case-insensitive. Here is the example code. month_conversions = { "Jan": "January&...
BobDylanMadHatter's user avatar
0 votes
1 answer
153 views

Jupyter notebook giving syntax error to codes

Greeting everyone Please what could be responsible for Jupyter notebook outputting Name error messages to my lines of codes it had correctly run just some moments ago? Please someone should assist me. ...
MikeO's user avatar
  • 1
-2 votes
3 answers
60 views

Cannot convert string variable to raw

I have seen few examples on how to convert string variable to raw one using interpolation, but it doesn't work for me: import json j = '{"value": "{\"foo\": \"bar\"}...
Roman Newaza's user avatar
  • 11.7k
-1 votes
1 answer
71 views

How to read a string value from a dict that has special character forwardslash in python

I have an input coming as dict and assigned it to variable 'var_1' input: { "key_1":"value_1", "key_2":"12345/6789-0ab1" } Assigning input to a ...
Nani's user avatar
  • 75
0 votes
3 answers
94 views

How do I convert a normal string in another format?

How do I convert a normal string in another format using Python script? For exp: a normal "String" into BOLD "String" or other format fonts! I tried with these two modules but ...
Troy9090's user avatar
-1 votes
1 answer
76 views

Learning python Python TypeError: not enough arguments for format string [duplicate]

I am new to python and trying to learn the basic just learned how to format string today and couldn't figure out what is wrong with this line of codes data = ["Zac", "poor fella", ...
Zack's user avatar
  • 3
0 votes
1 answer
71 views

Can someone help me understand this bit of string formatting?

I was trying a coding challenge and gave up, in the submitted answers for others I found this string formatting method. number = 10 for i in range(1, number+1): print("{0:{w}d} {0:{w}o} {...
Alasdair Pirie's user avatar
-3 votes
5 answers
468 views

how can I find the position of the last LETTER in a string in python?

I want to include a function in my code that can return the position in the string that the last letter in the string can be found. e.g: if the input were " hello world k ...^&", the ...
Coding Pigeon's user avatar
-2 votes
1 answer
160 views

Format string with substrings

I need to format a string with substrings of a variable. If I do: sample="1234567890XXXX" f"{sample[:5]}/{sample[5:10]}/{sample}/config" It works fine: '12345/67890/1234567890XXXX/...
FGV's user avatar
  • 165
0 votes
1 answer
58 views

Python Pandas: Confirm if a substring of DataFrame A is part of a string in DataFrame B

I have two dataframes: import pandas as pd countries_list_a = pd.DataFrame({'Country' : ['Australia', 'United Kingdom', 'United States'], 'Code' : ['A', 'B', 'C']}) countries_list_b = pd.DataFrame ({...
JohnRambo's user avatar
-2 votes
5 answers
428 views

Python Nested lambda function

Would there be a way to write a nested lambda function? The following is what I am trying to do: s = '123 there' f = lambda x: x.split() g = lambda x: [int(x[0]), x[1]] #g(f(s)) returns [123, 'there']...
James C's user avatar
  • 210
-3 votes
1 answer
79 views

Could you please explain below three codes?, why they are giving different results

code 1 list_a = [] list_a += str(1) O/P: ['1'] code 2 list_a = [] list_a += 1 O/P: Type Error code 3 list_a = [] list_a = list_a + str(1) O/P: Type Error I'm expecting that if += operator ...
Bhuvana ravula's user avatar
0 votes
3 answers
107 views

Find and delete/replace a part of bigger string

In my python/Django project, I am trying to write a custom exception class where I want to avoid showing few things to the end user. In the below error message, if you see the project name prj-eng-d-...
sandeep's user avatar
  • 3,345
2 votes
2 answers
66 views

How to get the callable function defined by exec() in Python?

Say I want to have a function exec_myfunc that can execute any user-defined function with an input value of 10. The user is supposed to define the function by a string as shown below: func1_str = &...
Shaun Han's user avatar
  • 2,785
-1 votes
2 answers
118 views

Is there a way to search from the back of a string in python using regex or any similar method?

I have text that can take multiple different forms with dashes in them. Examples: "'Super-rainbow' time to fight - 22-50t", "'m-m-m' title destroyer - 20t", "'eating food' ...
Matthew Smith's user avatar

1
2 3 4 5
110