All Questions
Tagged with python-2.7 string
1,417 questions
-1
votes
1
answer
38
views
Python search for the errors in the JSON
Premise: those dictionaries are strings. Those are JSON with a bad format. I search for the errors inside those JSON and print them.
example 1:
input
{
"ced": {
"CED_PH2&...
1
vote
1
answer
55
views
Why is my code not displaying firstNotRepeatingCharacter in the string, in Python?
So, I am solving this code signal problem and it's problem statement is as follows
Given a string s consisting of small English letters, find and return the first instance of a non-repeating ...
0
votes
1
answer
30
views
if statement homework error, how do i fix it? [duplicate]
I have some intro to python homework I can't seem to get right.
The question is : "Write a program to determine how much to tip the server in a restaurant. The tip should be 15% of the check, ...
0
votes
1
answer
42
views
Change order of characters in string randomly keeping the format in python [closed]
I have to mask some data but it is important to keep the format of it.
So I have differents strings like:
x = "0 1-111-555"
y = "000000-2022-1000253"
z = "01-702-1424"
t =...
0
votes
0
answers
334
views
Porting Python2 to Python3 - Reading Bytes from a socket and using unpack() correctly
There is code here that I am trying to convert from Python2 to Python3. In this section of code, data is received from a socket. data is declared to be an empty string and then concatenated. This is ...
0
votes
1
answer
78
views
Can you change the string of an instanced string class
I have this class:
class A(str):
def __str__(self):
return "the string"
def __repr__(self):
return "the repr"
a = A("change me")
...
0
votes
0
answers
63
views
Can you set the instance of an Object Class as a string input
Can you set the object class return as a string?
I have tried setting the object class with the __str__ and __repr__ methods overwritten.
class A(object):
def __str__(self):
return "...
0
votes
2
answers
43
views
code for Addition three minus one variable numbers
How to get from a list [7,0,8] from [7, 0, 8]? in python
This is my code
l3=input()
l5=l3.translate({Ord("["):None})
l1=l5.translate({Ord("]"):None})
l6=input()
l7=l6.translate({...
0
votes
1
answer
119
views
String comparison in tuple or list. Python2 vs Python3
We all probably agree that to compare two strings:
var = "MyString"
print(var is "MyString") # This is not the way we would do it (we don't what to compare the ID)
print(var == &...
-2
votes
2
answers
872
views
Fill in the gaps in the initials function so that it returns the initials of the words contained in the phrase received, in upper case
#original code
def initials(phrase):
words = phrase.___
result = ""
for word in words:
result += ___
return ___
print(initials("Universal Serial Bus&...
0
votes
1
answer
44
views
Change url formatting in Jupyter Python
Hey im trying to change 2 parts of a string, first is the last char, second in the mid of the string:
*nkw= will be cat: "sport , elec..."
*pgn= 1 , 2, 3, 4 ....
there is 2 loops because i ...
-1
votes
2
answers
79
views
how to compare given date (string) is current date to last 8 date or not? [closed]
I have an one date in a string. How can I figure out this date REFRESH = ("2021-11-25 00:27:23") to current date from last 8 days
from datetime import datetime
from datetime import ...
0
votes
2
answers
50
views
Replace a certain part of the string which matches a pattern in python 2.7 and save in the same file
I am trying to achieve something of this sort
My input file has this kind of entries
art.range.field = 100
art.net.cap = 200
art.net.ht = 1000
art.net.dep = 8000
I am trying to match the pattern like ...
1
vote
4
answers
665
views
How can i remove only the last bracket from a string in python?
How can i remove only the last bracket from a string ?
For example,
INPUT 1:
"hell(h)o(world)"
i want this result:
"hell(h)o"
Input 2 :-
hel(lo(wor)ld)
i want :-
hel
as you ...
0
votes
2
answers
377
views
Get all rows in a Pandas DataFrame column that are in a list of strings - This pattern has match groups
Consider the code
import pandas as pd
# dfs
df_sample = pd.read_csv('...........')
array = ['' , '' , '' ....]
pattern = '|'.join(array)
# get all the rows
print(df_sample.COLUMN_NAME_XXX.str....