-1
votes
2answers
34 views

Python RegEx get specific text

I'm new to RegEx. I am using python to go through a web page and pick out certain text. I have been able to pick out part of what I need with some extra character attached. In the example below I am ...
1
vote
4answers
40 views

Pythonic methods of returning the longest word in a string

I understand finding the longest word within a string has been asked and answered numerous times but I would like to know the difference between the following methods, and why one would use approach A ...
0
votes
3answers
34 views

Having trouble with whitespace and strings in a function

Prompt Turn a string into rollercoaster case. The first letter of the sentence is uppercase, the next lowercase, the next uppercase, and so on. Code with open('test.txt') as file: for line ...
-1
votes
1answer
36 views

Python: remove characters from a string? [on hold]

I took a python course back when i was in high school but now I barely remember anything about it. I'm bored today and though I should try some python exercises. Example: string = '3dc8uo8c33a ...
1
vote
2answers
29 views

Beginner not sure how to join lists while scraping

Hello I am trying to scrape www.allocine.fr for the latest movies I made the following script: # -*- coding: utf-8 -*- import urllib import re page = ["?page=1", "?page=2", "?page=3"] i=0 while ...
1
vote
2answers
27 views

Python issues output. String manipulation

I got the following code, however at the time of the output (txt file) it will not return a value just a "None" however that happensw when I save it to a txt file, when I simply run the program it ...
-7
votes
3answers
22 views

print all names of special files in the current directory: [duplicate]

How can i get all the names of files with a special format (for example .jpg and .mp3 and ...) in the current directory and save them in a text file ? I know it's possible with other lib but i want ...
-2
votes
0answers
26 views

string for loop for more than 1 char python [duplicate]

Just a general question In python 2.7, is there a way that I can get more than one character in a for loop? For example if I have the string: 'AABBCCDD' I would like to have a for loop that goes: ...
1
vote
2answers
52 views

Add a string to each individual string in a list

Simple addition of a string and a list of strings yields the error cannot concatenate 'str' and 'list' objects. Is there a more elegant way to do the following (e.g. without the loop)? ...
2
votes
3answers
58 views

I want to take characters from a string and populate those characters in 2 different sets in python?

comp = "{1},{2},{3},{1,2},{2,3}" I want the above string to be distributed to 2 different sets. S0_list = [{1},{2},{3}] and S1_list = {1,2},{2,3}. The code basically has to run through each character ...
0
votes
3answers
35 views

Remove all elements of a list that are substrings of other elements of the list in python

I have the following list: people = ['John', 'Maurice Smith', 'Sebastian', 'Maurice', 'John Sebastian', 'George', 'George Washington'] As you can notice, John, Maurice, Sebastian and George are ...
1
vote
4answers
35 views

Stuck on iterating through a list and returning True when a string ends with another string from the list

I receive a set of strings. I convert that to a list. I need to return a value of True if any of the strings in the list are a suffix of any other string in the list. For example: test = ...
-5
votes
1answer
20 views

EOL while scanning string literal, file won't run

I've checked it over 30 times, I have no clue what's wrong with the string. It must be something minor that I just can't see. #Description print("Costs of EMS responses") Print("Choose the costs ...
-1
votes
0answers
30 views

python charset converting error

I receive a string from a java middleware, i use urllib2 open() and read(). After read() ,I get a string: ��¼�Ļ���Ϊ: v125193157.bja ; SCM������Ϊ: wb-gdsunwu ; �����ķ���Ϊ: �ճ� ; ��;: ...
-2
votes
2answers
31 views

Match everything inside multiple instances of a tag in a string in python

Sample string: str = "<sec>John</sec> said hi to a woman (named <sec>Mary</sec>)" Result should be a list: res = [John, Mary] I should really have learned regex by now.
2
votes
2answers
34 views

Binary numbers of N digits

for generating binary numbers in n digit i did this to get upto 16 binary numbers. n = 6 # for 6 digits for i in xrange(16): b = bin(i)[2:] l = len(b) b = str(0) * ...
0
votes
4answers
26 views

How can I select a string using start and endpoints (characters)?

How can I select a string in python knowing the start and end points? If the string is: Evelin said, "Hi Dude! How are you?" and no one cared!! Or something like this: Jane said *aww! thats cute, ...
0
votes
1answer
28 views

Splitting String in python and convert to json

I'm having a string like this : {'4': {1, 2}, '2': {1, 2}, '0': {1, 2}}["eq('2', '0')", "eq('2', '4')", "eq('0','4')"] And I only need everything before ["eq('2'.... so I only need to save {'4': ...
1
vote
2answers
45 views

match pattern to its counterpart from a list of patterns

In Python, I want to have a pair like this: patterns: abc, def ghi, jkl mno, xyz The idea is: given a string, I want to search for occurrence of any of the pattern p from patterns and when I find ...
-2
votes
3answers
35 views

Counting occurence within a string Python

I am writing a code to count the occurrences of each letter within a string. I understand that it has been asked and answered Count occurrence of a character in a string, however I cannot figure out ...
0
votes
2answers
31 views

python - get target line in a file etc. then get a specific previous line?

I need to find a certain line in some output. I can do this, but then having found the right part of the output, I need to extract certain lines before that one. for i, line in enumerate(lines): ...
0
votes
2answers
52 views

Mirroring a string of text using Python

I am trying to write code to mirror a string within python. I assumed it was similar to mirroring an image or a sound however I cannot get past the loop. The input and output should both be a string. ...
0
votes
1answer
30 views

Split string on comma when field contains a comma

Consider the following string: '538.48,0.29,"533.59 - 540.00","AZO",102482,"+0.05%","N/A",0.00,535.09,"AutoZone, Inc. Co",538.77,"N/A"' I need to split this into a list so it looks like the ...
0
votes
1answer
29 views

Python regular expression to print out sections of a string

Here is my code (apologies for the lengthiness of testString, I was not too sure how to format it): testString = ...
0
votes
1answer
21 views

Complexity of appending to front of python string

What's the time complexity of appending to the front of a python string?
0
votes
2answers
29 views

Remove negative sign in string format in python

i'd like to know if it is possible to remove the negative sign from '{:,.2f}'.format(number) only using format. So that '{:,.2f}'.format(10) ## 10 '{:,.2f}'.format(-10) ## 10 Thanks in advance
0
votes
1answer
17 views

Recovering list saved in textfile as string, turning it back into list

Newbie question after four hours of research. I wrote a program that saves formulas in a textfile in string format: ['myminus', 'IBM', 'Low', 'myplus', 'IBM', 'Close', 'WMT', 'Low'] When I read ...
2
votes
2answers
45 views

how to split a string by characters which occur in another list?

I'm trying to split a string as soon as I see a symbol which is in my symbol list (it's quite a big list) . now something that I want to know ,as a new python user , is there a method not the split ...
0
votes
1answer
17 views

Converting non ascii characters to ascii from dictreader

There are many questions on python and unicode/string. However, none of the answers work for me. First, a file is opened using DictReader, then each row is put into an array. Then the dict value ...
-1
votes
0answers
22 views

How can I take a time value from raw user input in Python 2.7

So basically I'm trying to make a sleep timer and I need something to let me turn the value from raw_input() into a hardwired time format, like when I can turn the input from a user, normally ...
0
votes
0answers
13 views

Python RSA string to int \n newline

For a CTF competition, I had to find the public key modulus of an RSA encryption program, where I could enter as many plaintexts as I wanted and would receive ciphertexts all encoded with the same ...
0
votes
2answers
24 views

Print function attribute

In one module, I am trying to gather raw_inputs and join each, with a space. Then, I want to print out the result of a single raw_input: def human_infoz(): name = raw_input("Enter human ...
0
votes
2answers
37 views

How to get three integers from a specific line in a file with Python?

I have a (ASCII) file, foo.txt, which has a lot of stuff in it but I only care about the three numbers on line 2 (separated by white space). For your information (I don't know if it will be relevant) ...
-2
votes
3answers
53 views

how to pick chars from a string in defined but different sized steps?

I want to pick chars from a string in two changing steps, lets say the 1st and the 9th char, the 10th and the 19th and so on through the whole string. What is a fast & pythonic way to do so?
-1
votes
3answers
36 views

How do I create and if condition for strings in python [closed]

Hello I've been trying to get this line of code working but it keeps going down to the else: statement. Any ideas? I cant understand what I'm doing wrong for it not to accept the if: condition. ...
0
votes
1answer
17 views

Python: Extract all characters between a two groups of characters in a string

Say I have a list of strings corresponding to a file name: files = ['variable_timestep_model321_experiment123.csv', 'variable_timestep_model2_experiment21.csv', ...
-1
votes
0answers
38 views

Score Strings by position from .csv [closed]

So, I have a CSV file that contains sub-strings in different sizes from a main string. I want to split the sub-strings in characters and score them based on the frequency that each character appears. ...
0
votes
3answers
30 views

Reversing str.translate in Python

If I want to remove the numbers from "He123llo Wor456ld!" with translate, I can from string import digits str = "He123llo Wor456ld!" str = str.translate(None, digits) print str >> Hello World! ...
-3
votes
1answer
24 views

number string to list of numbers conversion

I have a string a = 2,00,02 each element of this string has datatype str. I want to convert it to a list such as a = [2, 00, 02] so a is a list and each element of a should have datatype int ...
7
votes
1answer
306 views

Why is variable1 += variable2 much faster than variable1 = variable1 + variable2?

I have inherited some Python code which is used to create huge tables (of up to 19 columns wide by 5000 rows). It took nine seconds for the table to be drawn on the screen. I noticed that each row was ...
2
votes
2answers
36 views

python list comprehensions invalid syntax while if statement

I've got list like this z = ['aaaaaa','bbbbbbbbbb','cccccccc'] i would like to cut off first 6 chars from all elements and if element is empty not to put in another list. So I made this code: [x[6:] ...
-2
votes
2answers
69 views

Fantasy Football Scorer Python

I need to create a program which reads a text file which contains a list of soccer players and have corresponding points to it. it asks for soccer players until there is no output and then it totals ...
0
votes
2answers
48 views

for k, v in dict ///// TypeError: 'str' object is not callable

import getpass class LogInNow(object): def __init__(self, file): self.openfile = open(file, 'r') self.readfile = self.openfile.read() def authenticate(self): ...
-1
votes
1answer
24 views

String search for recursive matches in python

I want to return a tuple of the starting points of all matches of a key in a given target string. My code uses the slicing operation and hence returns the relative position from the new sliced ...
0
votes
1answer
45 views

Write new file by matching strings from input file

I have a few naive questions about scripting with Python. I have some input files of the form "{1,g,{Frog,12}}",(x**2+.7*x)/2**x "{2,{g,h},{Pig,17}}",(.8*x**3-1.3*x)/2.5**x etc., where the the ...
-1
votes
2answers
54 views

how do i make a bunch of words into a list?

I've got a random bunch of words and I need to make it into a list, but there is a problem, I must take the words as they are and convert them into a list in the program itself. for example I got this ...
0
votes
1answer
28 views

Python: How to Add Specificly Characterized text To A Text File

I am writing a program using the Python Programming Language. Here is a part of my python script: #!/usr/bin/python import os import time import sys print "Creating new text file" file = ...
1
vote
3answers
68 views

Best way to identify some string in Python

I'm writing a system to read data coming from devices that do the tracking of trucks. This system will receive information of different types of equipment, thus being the trace strings that will ...
-8
votes
2answers
42 views

python evaluate length of a string [closed]

I need to evaluate a string in Python but I get an error. This is my code: def is_valid(line): arr = line.strip().split(';') print(len(arr[0]) if len(arr[0]) != 39: return False ...
1
vote
1answer
51 views

How to create a C-string containing binary raster-data of a ppm image

I have a little problem concerning string generation in C. The following code snippet is part of a C Extension for a Python/Tkinter app which generates images (mandelbrot, gradients and such). Before ...