All Questions
133 questions
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
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 ...
1
vote
4
answers
666
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
1
answer
83
views
What is the exact python3 equivalent of python2's unicode(v, errors='ignore')?
What is the exact python3 equivalent of python2's unicode(v, errors='ignore') ?
Note that:
v is any string (e.g. six.string_types)
errors='ignore' is crucial
Thanks!
0
votes
0
answers
17
views
When I run this python command in the interpretor, I get a TypeError [duplicate]
So I was running the command 'first={0[0]}, last={0[-1]}'.format(somelist) where somelist = ['s','p','a','m']. I get an error which says TypeError: list indices must be integers or slices, not str.
...
0
votes
2
answers
60
views
Split the content in the list to required output
I am working on a personal project and I am stuck at a point. Any suggestion is appreciated
My input is this
>>> mylist = ["'(select envrnmnt_parm_value from envrnmnt_parm where ...
0
votes
2
answers
67
views
How to fetch text after another text in python with different symbols to split?
I need to fetch the ID created i.e 1255325456 but I am not able to split it and get this value.
My step
Extract the line in which 'ID Created' is written .
After fetching , I m splitting it , but ...
-1
votes
1
answer
112
views
How can I pass an argument in a class?
We are migrating to Python 3 and I want to pass a string as an argument to a class, but I'm getting the error:
str() argument 2 must be str, not tuple
if _python3_available():
param_urllib = "...
-2
votes
2
answers
253
views
How to extract a list of substrings using recursion?
Given a string say,
strr = "int a; int b; int c;"
How can I extract a list from this string containing elements like ['int a', 'int b', 'int c'].
I want to achieve this output with recursion ...
-2
votes
2
answers
67
views
Slicing List or String Object in Python [duplicate]
What is the default range in slicing:
For example:
ls = [1, 2, 3, 4, 5]
ls[-3::1] #returns copy of the elements at indexes -3, -2, -1
ls[-3::-1] #returns copy of the elements at indexes -3 till the ...
-1
votes
3
answers
193
views
add up even numbers in list using two nested for loops and the str() function
I am trying to get all of the even numbers from the list, using two nested loops and using str(). My code works, just not how I am intending it to and it is short of what I am looking for.
def ...