Tagged Questions
1
vote
1answer
42 views
How do I print in Python 3.3.3 without carriage return?
First of all, I am NOT looking for how to print in the same line with the print(some_stuff, end="").
In Python 2.7 you could type:
while True:
for i in ["/","-","|","\\","|"]:
print "%s\r" % i,
...
1
vote
3answers
57 views
Doesn't remove from list
Im working with the next code:
for u in G:
if u.count('L')>1:
while (u in G)==True:
G.remove(u)
print G
Where G is a list of strings with the letters O,A and L.
The ...
1
vote
1answer
29 views
Regex sub function not working with unicode string
I'm trying to use Python's sub function and I'm having a problem getting it to work. From the troubleshooting I've been doing I believe it has something to do with the unicode characters in the ...
0
votes
1answer
27 views
“sample larger than population” in random.sample python
creating a simple pass generator for myself, i noticed that if i want my population to be digits only (0-9) which is overall 10 options, if i want my length over 10, it wont use any of the digits more ...
-3
votes
1answer
32 views
How to replace specific string in Django Template Language? [on hold]
I am working on Djingo template language.I am working on Forms and table which is taking some data from database and showing it in tables.
Now i want that if there is some value coming from database ...
0
votes
3answers
36 views
Python: hangman program
I am posting my question on stack overflow because I didn't know what to search and when I did the answers seemed completely irrevelant.
Anyways, this is my code:
from random import randrange
# - ...
3
votes
2answers
39 views
Automatic conversion of the advanced string formatter from the old style
Is there any automatic way to convert a piece of code from python's old style string formatting (using %) to the new style (using .format)? For example, consider the formatting of a PDB atom ...
0
votes
0answers
16 views
Error with StringVar “get” method inheritance with ttk
I'm using Python 2.7.5 on a Windows 7 machine.
I defined a subclass of the Tkinter StringVar that triggers the execution of a specified function when the variable is set. I just started ...
2
votes
5answers
52 views
program to extract every alternate letters from a string in python?
Python programs are often short and concise and what usually requires bunch of lines in other programming languages (that I know of) can be accomplished in a line or two in python.
One such program I ...
1
vote
3answers
25 views
Function string.lstrip() returns blank string in python
In the python interpreter:
'pradeep'.lstrip('prade') gives an output of ''.
I was expecting this to return 'ep'.
Why is that assumption wrong ?
-1
votes
1answer
29 views
Python: Text saving issue
I recently started python, and was coding a text editor in the python console for a project. I have a string array (if I remember it was called that) and each string holds a line of the text (it can ...
0
votes
3answers
31 views
Unhexlify errors when converting 50 character string
I want to convert WKB representations of XY coordinates into a YX format. The code I'm using works with 42 character WKB strings, but when I use it on 50 character strings it gives me an odd YX ...
0
votes
2answers
54 views
What is the Ruby String sub function?
I'm trying to convert a Ruby script into a Python script (having absolutely no understanding of the various functions in Ruby) and can't find anything on the Ruby sub function.
Here's the function ...
2
votes
2answers
44 views
Efficient String Concatenation in Matlab
A while ago I stumbled upon this document. It assess the performance of several concatenating methods in python. Here are the 4 out of the 6 methods that it compares:
Python String Concatenation ...
2
votes
1answer
22 views
Python find value of view state given source
I am trying to write a program to decode view state given a url. I know similar programs exist but this is more of an excursive than a project.
Given the html source of a page, how can I get the value ...
-4
votes
3answers
42 views
How to remove all the text in a string between two sub-strings. Python 2.7 [on hold]
I need a function that will look through a string and remove everything that is in between two strings,"About DoctorTardi" and "Stats for Project Ares".
The answer is probably staring at me in the ...
0
votes
1answer
44 views
Eliminate space in a string found on the same line that a specified string
I'm new to python and this would be my first coding. I saw topics with similar problems to the one I am trying to resolve, but since I am new, I can't really figure where to go (hot to adapt it for ...
1
vote
1answer
33 views
how to limit possible input while using raw_input? (also using split)
i want to limit the users input in two cases:
1.With a string and split, when asking the user to put in two, 2 digit numbers I wrote:
x=raw_input("words").split()
I want to only enable him to ...
0
votes
2answers
45 views
Search a list for a string and store it in Python
I have a list of strings generated from a text file and I need to test an input string to see if it has any of the words in my list. I then need to store the matching string/strings so that they can ...
0
votes
1answer
78 views
How to make iterator to start from a specific index?
I want to use iterator over a string from a specific index which is not the beginning, without using slicing. Is there a way doing this? I'm using python 3.2
Edit: I need to write a generator ...
1
vote
1answer
29 views
Sequenced string PK's in python
i'm looking for optimal string sequence generator that could be used as user id generator. As far as i get it should implement following features:
Length is restricted to 8 characters.
Consists from ...
0
votes
0answers
19 views
python string template : Error 'must be convertible to a buffer, not Template'
I use httplib and a string template.
With a normal String as message, it is working, with a template I get :
Error 'must be convertible to a buffer, not Template'
...
1
vote
4answers
101 views
Using asterix character (*) as joker in python string replacement?
I am a beginner in python an am currently struggling with something:
I want to make a couple of changes in a single string.
Is it possible to use a single asterix sign (*), as a replacement-joker for ...
6
votes
3answers
75 views
Case Insensitive Python string split() method
I have 2 strings
a = "abc feat. def"
b = "abc Feat. def"
I want to retrieve the string before the word feat. or Feat.
This is what I'm doing,
a.split("feat.", 1)[0].rstrip()
This returns abc. ...
1
vote
2answers
52 views
How to find a specific character in a string and put it at the end of the string
I have this string:
'Is?"they'
I want to find the question mark (?) in the string, and put it at the end of the string. The output should look like this:
'Is"they?'
I am using the following ...
0
votes
5answers
69 views
How to find out if str has any number [closed]
I have a question. If I have a string, for example:
str1 = 'Wazzup1'
and numbers:
nums = '1234567890'
I need a code that will look into str1 and tell me if it has any number(not all of them). ...
4
votes
2answers
69 views
How can I convert a unicode string into string literals in Python 2.7?
Python2.7:
I would like to do something unusual. Most people want to convert string literals to more human-readable strings. I would like to convert the following list of unicode strings into their ...
0
votes
1answer
39 views
Why am I getting “AttributeError: 'module' object has no attribute 'replace'” on string.replace()
The line causing the error is
totalR = totalR + (float(string.replace(contri[0][5],",","")) + float(string.replace(contri[0][6],",","")))
contri[0][5] and [6] are strings that contain numbers ...
0
votes
3answers
55 views
Combinations without using “itertools.combinations”
What I'd need is to create combinations for two elements a time.
if a list contains: seq = ['A', 'B', 'C']
the output would be com = [['A', 'B'], ['A', 'C'], ['B', 'C']]
all this without ...
-2
votes
3answers
71 views
Dictionary string formatting [closed]
Pickaxes = {
'adamant pickaxe': {'name': 'adamant pickaxe', 'cost': 150, 'sell': 100},
'bronze pickaxe': {'name': 'bronze pickaxe', 'cost': 10, 'sell': 1},
'dragon pickaxe': {'name': 'dragon ...
2
votes
3answers
40 views
Find frequency of array strings in a file sized string, using Python
I've looked at a lot of answers, which are aimed at finding the occurrence of every word in the file, or big string or even arrays. but I don't want to do this, nor are my strings coming from a text ...
1
vote
3answers
63 views
Python and flipping the order of lastname, firstname
I have a string such as smith, bob;jones, bill;doe, john that is coming from a CSV file. I would like to extract the names and flip the order of the last name and first name to be first name then ...
0
votes
1answer
14 views
Split multi-line string with shlex and keep quote characters
How do I split a string with Python's shlex while preserving the quote characters that shlex splits on?
Sample Input:
Two Words
"A Multi-line
comment."
Desired Output:
['Two', 'Words', '"A ...
0
votes
0answers
34 views
how to import the value of an object I copied (ctrl, c) into a string in python
I'm trying to use a value I copied into a web page with selenium as a variable for my python program, but I can't. The only thing I got since now has been just to paste that value, that actually is a ...
1
vote
4answers
109 views
Faster method of evaluating a boolean expression as a string in Python
I have been working on this project for a couple months right now. The ultimate goal of this project is to evaluate an entire digital logic circuit similar to functional testing; just to give a scope ...
6
votes
3answers
68 views
Concatenate elements of a tuple in a list in python
I have a list of tuples that has strings in it
For instance:
[('this', 'is', 'a', 'foo', 'bar', 'sentences')
('is', 'a', 'foo', 'bar', 'sentences', 'and')
('a', 'foo', 'bar', 'sentences', 'and', 'i')
...
0
votes
1answer
40 views
Unicode strings to byte strings without the addition of backslashes
I'm learning python by doing the python challenge using python3.3 and I'm on question eight. There's a comment in the markup providing you with two bz2-compressed unicode strings outputting byte ...
0
votes
3answers
29 views
Function font_back - Error
This is a question from http://codingbat.com/, where I am practicing my new skills on Python. So what I want is to given a string, return a new string where the first and last chars have been exchange ...
1
vote
3answers
73 views
python string every two chars to byte - do it fast
Got a binary blob string like:
input = "AB02CF4AFF"
Every pair "AB", "02", "CF", "4A", "FF" constitute a byte.
I'm doing this:
data = StringIO()
for j in range(0, len(input)/2):
bit = ...
0
votes
1answer
40 views
How to extract a list of strings out of single string by using regex?
I have a long string that is actually a set of concepts. I want to mine the string and to create a list of concepts.
The string begins with:
Abduction and retroduction Action research: a case study ...
2
votes
2answers
51 views
Compare 2 strings without considering accents in Python
I would like to compare 2 strings and have True if the strings are identical, without considering the accents.
Example : I would like the following condition to be true :
if 'séquoia' in 'Mon ...
0
votes
2answers
63 views
Only take from the latest string with python regex
I using regex in my Python application.
The string that I run on with regex contains many lines.
String (a portion of the string i using):
36% [============> ] 55.5 / ...
-2
votes
5answers
50 views
Percentage of how similar strings are in Python? [closed]
I don't know how to do a program that gives a percentage of how similar two strings of the same length are.
For example, for abcd and abce it should give 75%.
The order matters, I don't want that it ...
0
votes
6answers
53 views
How to check is a string contains only characters in a given set in python
I have a a user inputted polynomial and I only want to use it if it has only characters in the string 1234567890^-+x.
How can I check if it does or not without using external packages? I only want to ...
0
votes
4answers
49 views
How to enter a large string in python? [closed]
I'm working in a program that needs to compare strings that have about 900 digits.
But whenever I enter them as
a = ...
2
votes
4answers
69 views
Find + Find next in Python
Let L be a list of strings.
Here is the code I use for finding a string texttofind in the list L.
texttofind = 'Bonjour'
for s in L:
if texttofind in s:
print 'Found!'
print s
...
6
votes
2answers
72 views
Are there downsides to using Python locals() for string formatting? [Superior to a [duplicate]
But the above linked question is of lower quality.
One might expect an error here, but we can provide the str.format method with unused keyword arguments.
>>> '{a}{b}'.format(a='foo', ...
6
votes
4answers
5k views
Python spacing and aligning strings
I am trying to add spacing to align text in between two strings vars without using " " to do so
Trying to get the text to look like this, with the second column being aligned.
Location: ...
2
votes
2answers
579 views
How to display string which contains django template variables?
Let's say I have an string variable called *magic_string* which value is set to "This product name is {{ product.name }}" and it's avaible at django template. Is it ever possible to parse that ...
274
votes
2answers
109k views
Reverse a string in Python
There is no built in reverse function in Python's str object. What is the best way of implementing this?
If supplying a very concise answer, please elaborate on it's efficiency. Is the str converted ...