Tagged Questions
0
votes
3answers
24 views
Python: checking each letter to see if it contains all letters needed, this code isn´t working
I need to check if all the letters that form a given word are contained inside a given string. I´ve tried something but isn´t working:
def check(texto, control):
for letra in control:
if ...
0
votes
3answers
48 views
String Manipulation Python
I am trying to modify a string , by replacing each alphabet by an alphabet which is two postions ahead of it. e.g. 'a' replaced by 'c', 'b' replaced by 'd'. The only exceptions is 'y' should be ...
2
votes
4answers
42 views
How to check if elements of a list are in a string
The inverse of this question (finding a string in a list) is so popular, that I wasn't able to find an answer to my question.
black_list = ["ab:", "cd:", "ef:", "gh:"]
for line in some_file:
if ...
1
vote
2answers
91 views
Why does 20130708 < “” return true in Python?
>>> 20130708 < ''
True
>>> 20130708 > ''
False
I am not sure what the explanation for this is. The wikipedia article on lexicographical ordering says that
u < v if u ...
1
vote
1answer
16 views
Difficulty with using Lists to search in xlrd
I am trying to write a program which takes the cells from the first column of an excel file (a last name), and search for that string within the text of the cell adjacent to it in the same row.
...
3
votes
2answers
64 views
How do I convert only specific parts of a string to uppercase in Python?
So I am writing a function that takes in a string input (ex: abcdefg) and a shorter portion of that input (ex: cde) and searches for it within the first longer string.
How do I make it so that only ...
3
votes
2answers
112 views
Writing numbers from 0 to 1000000000
I am trying to write a list of the numbers from 0 to 1000000000 as strings, directly to a text file. I would also like each number to have leading zeros up to ten digit places, e.g. 0000000000, ...
2
votes
1answer
87 views
Sorting strings of different length with digit suffix
I have a a list of lists, based on the first element of each list I want to sort the list. Sample of these indices:
vlan1
usb0
eth1
...
1
vote
1answer
38 views
How to use str.replace() with a dictionary of replacements? Python
Given a dictionary of replacements, where key = to be replaced and value = replacements, e.g.:
replacements = {u'\u2014':'-', u'\u2019':"'", u'\u2018':"'", u'\u201d':'"', u'\u201c':'"'}
How do i ...
-1
votes
3answers
57 views
What are \xHEX characters and is there a table for them?
When reading a textfile, I read these characters, when printed out to console it outputs blanks or �:
['\x80', '\xc3', '\x94', '\x99', '\x98','\x9d', '\x9c', '\xa9', '\xa6', '\xe2']
What are these ...
2
votes
2answers
43 views
How do I strip a string given a list of unwanted characters? Python
Is there a way to pass in a list instead of a char to str.strip() in python? I have been doing it this way:
unwanted = [c for c in '!@#$%^&*(FGHJKmn']
s = 'FFFFoFob*&%ar**^'
for u in ...
0
votes
3answers
51 views
Calculate from list of strings - Python
I've got a python formula that randomly places operands in between numbers. The list could, for example, look like this:
['9-8+7', '7-8-6']
What I want to do is get the value of each string, so ...
2
votes
5answers
68 views
Replacing a string with counts of streaks
Let's say I have a string of the following form:
"000000111100011100001011000000001111"
and I want to create a list containing the lengths of the 1-streaks:
[4, 3, 1, 2, 4]
Is there a nice ...
6
votes
2answers
84 views
Python's “re” module not working?
I'm using Python's "re" module as follows:
request = get("http://www.allmusic.com/album/warning-mw0000106792")
print re.findall('<hgroup>(.*?)</hgroup>', request)
All I'm doing is ...
0
votes
6answers
42 views
How to read and store values from a text file into a dictionary. [python]
Here is the information in the file:
Part no. Description Price
----------------------------------------
453 Sperving_Bearing 9900
1342 Panametric_Fan 23400
9480 ...