All Questions
14 questions
9
votes
6
answers
1k
views
check if letters of a string are in sequential order in another string
If it were just checking whether letters in a test_string are also in a control_string,
I would not have had this problem.
I will simply use the code below.
if set(test_string.lower()) <= set(...
16
votes
9
answers
4k
views
Python 3: Perfect Alphabetical Order
The goal of the code is to find the longest alphabetical substring within a string.
s = 'xyzbcdezzz'
longest_string = ''
current_string = ''
stringcount = 0
for n in range (len(s) - 1):
if s[n] ...
-3
votes
5
answers
5k
views
I'm trying to replace a character in Python while iterating over a string and but it doesn't work
This is the code I currently have:
letter = raw_input("Replace letter?")
traversed = raw_input("Traverse in?")
replacewith = raw_input("Replace with?")
traverseint = 0
for i in traversed:
...
0
votes
2
answers
70
views
Python list to string
Element3 of each list is a list (in brackets). I want element3 to be a string 'store1.txt' not ['store1.txt'].
store_list = [["Freds", "store1"], ["Sams", "store2"], ["Johns", "store3"], ["Toms", "...
-4
votes
3
answers
101
views
for var in string returning all vars in string Python
My code:
text="Qmfbtf fbu nf"
for f in text:
print "f"
In an ideal situation the output would print 4 f's
However it is returning one f per character in the string.
It seems to be using my ...
9
votes
6
answers
10k
views
Preventing a Python For-loop from iterating over a single string by char
I have a variable which can be a single string or a list of string. When the variable is a single string , the loop iterates it by char.
text = function() # the function method can return a single ...
0
votes
0
answers
37
views
How to get the index of duplicates in a string [duplicate]
Python cannot seem to differentiate between duplicates of the same letter. For example:
word = "australia"
variable = "a"
for letter in word:
if variable == letter:
index = word.index( ...
1
vote
1
answer
441
views
Issue with iterating through list of callable
I am having an issue with iterating over a list of callables in python. The callables are supposed to be called on a generator of strings. The current behaviour is that the last callable in the list ...
0
votes
1
answer
21
views
Pull a desired value (integer) from a string, that is inbetween two underscores
Strange one, I have lots of folders named for example:
141110_0.7_armt_amb2_4_load_haut_pag_-40.74_75.06_
or
141110_0.7_armt_amb2_5_load_haut_pag_-40.74_75.06_
I want to pull the integer value (...
-1
votes
1
answer
1k
views
In python, how do I find the positions of a word that occurs more than once in a sentence using a for loop?
Basically, i need to make a python 2.7 program where the user inputs a sentence, then inputs a word, and if the word is in the sentence, the program displays its position(s). if the word is not in the ...
1
vote
1
answer
96
views
Loop through Oracle Cursor and Save excel file as string variable
import CX_Oracle
Import xlwt
SQL0 = "SELECT COUNTRY FROM COUNTRYLIST"
cursor0 = con.cursor()
cursor0.execute(SQL0)
for country in cursor0:
SQL = "SELECT * from TABLE WHERE COUNTRY = %s" % country
...
-2
votes
1
answer
88
views
Trying to append a list with immutable list of chars [Python]
so I'm trying to append a string of chars to a list, while changing the last char in the list as the loop proceeds. However, whenever I try to change the list of chars, all the previous chars become ...
0
votes
2
answers
80
views
looping through each element of a string and handling wildcard cases in python
I want to find if string1 is substring of string2.
e.g. string1="abc", string2="afcabcdfg".
I want to add Wildcard cases, e.g. "*" can substitute "a" and "c", "y" can substitute "f" or "d". As a ...
2
votes
2
answers
1k
views
Title case for a paragraph
I'm creating a markov chain algorithm. I output a variable called sentences which contains one string of sentences. I want to make the sentences sentence case so I wrote this:
for l in range(0, len(...