Tagged Questions
0
votes
1answer
23 views
String.count() returning 0 even though word exists in file
So this is a simple code trying to found the frequency of occurrences of a phrase ("every kind of asset") in a number of files.
import codecs
import glob
import os.path
filelocation = ...
0
votes
3answers
30 views
Python lambda to print formatted nested list
Practicing a couple things: lambda functions and string manipulations. I want to find the most efficient ways of doing this without importing anything.
so here's a short script that reorders a word ...
0
votes
1answer
40 views
store each word from a text file into a list
So I'm trying to make a program that reads a file, and stores each word into a list of strings. I can add each line into a list of strings, (see the code below) but how do I add each individual word ...
1
vote
4answers
44 views
TypeError when using replace() from dictionary
First of all: Please keep in mind that I'm very much a beginner at programming.
I'm trying to write a simple program in Python that will replace the consonants in a string with ...
-7
votes
1answer
57 views
Manipulating tuple to add ':' after first element
def display_info(records, data):
for row in records:
if data in row:
return row
for c in row:
if c in records:
return row
else:
...
0
votes
3answers
58 views
Handling strings in python
I have 2 strings:
s7="ONE : TWO : THREE : FOUR : FIVE 30.1 : SIX 288.3 : SEVEN 1.9 : EIGHT 45.3 :"
s8="ONE : TWO : THREE : FOUR 155.5 : FIVE 334.7 : SIX 6.7 : SEVEN 44.5 :"
I'm using the ...
1
vote
2answers
41 views
Python add a string to all set's elements
I'm wondering what is the Python way to perform the following -
Given a set :
s = {'s1','s2','s3'}
I would like to perform something like :
s.addToAll('!')
to get
{'s1!','s2!','s3!'}
Thanks!
...
0
votes
0answers
35 views
Searching a string and
I am trying to figure out how to find the rectangles I can make from the following string by using adjacent X's in python. I am relatively new to python and cannot figure out how to loop through this ...
1
vote
2answers
44 views
How to parse/format a string of tuples?
I jus wrote a grade calculating program and am down to the last few lines ... I have this string of tuples :
"('Jetson Elroy', '45', '88', '88', '70', 0.7253846153846155, 'C', 'Not Passible', ...
0
votes
2answers
54 views
Split specific items in list into two
I'm building an XML parser in python for an SVG file. It will eventually become specific instructions for stepper motors.
SVG files contain commands such as 'M', 'C' and 'L.' The path data might ...
0
votes
2answers
37 views
Search for specific string, copy into text file, if not there, produce error
This is similar to a previous question I asked. But I've decided to make it a little bit more complex.
I'm making a program that can read a textfile and copy a specific portion of the textfile into ...
0
votes
3answers
55 views
Python- how do i use re to match a whole string
i am validating the text input by a user so that it will only accept letters but not numbers. so far my code works fine when i type in a number (e.g. 56), it warns me that i should only type letters ...
0
votes
2answers
59 views
Convert string to function in python
I have a string coming from the database. This string is the name of a file .py that is within a module. The structure is this:
files
├── file1.py
├── file2.py
└── __init__.py
The file1.py ...
0
votes
1answer
20 views
match length of string with a string with the same length in a list
So if I have this:
a = "hi"
b = ["hello there", "goodbye", "nice to meet you"]
so if the len(a) is 2 then is it possible to find a string with the same length in b? In this case is "hello there"
...
0
votes
5answers
62 views
Python string comparison won't match forward slash
A simple question usually has a simple answer but I am struggling to find it. Can someone please explain why the following isn't matching?
string = 'HTTP/NONE'
if string is 'HTTP/NONE': print 'match'
...