0
votes
0answers
3 views

replace a string with regular expression in python

I have been learning regular expression for a while but still find it confusing sometimes I am trying to replace all the self.assertRaisesRegexp(SomeError,'somestring'): to ...
-1
votes
5answers
56 views

Python program won't work - very simple

Basically for this assignment I need to convert a name into a 'secret number' by summing the value I assigned each letter. Everything works so far but when I try to sum it up it gives me an error. I ...
0
votes
1answer
16 views

Having problems understanding a code about maketrans

def shift_string(text, shift): intab='abcdefghijklmnopqrstuvwxyz' outab=intab[shift:]+intab[:shift] return str.maketrans(intab, outab) shift_string("hello",5) When i run this, a blank ...
0
votes
4answers
57 views

String manipulation in Python (All upper and lower case derivatives of a word)

I have to read in a word, and create an array which stores every variation of upper and lower case characters for this word in an array. For example with the word "abc". I need to find a way to ...
5
votes
1answer
43 views

Splitting a string by using two substrings in Python

I am searching a string by using re, which works quite right for almost all cases except when there is a newline character(\n) For instance if string is defined as: testStr = " Test to ...
0
votes
1answer
24 views

Searching two things

I am using re and would like to search a string between two strings. My problem is the string that I would like to search may end with either newline(\n) or another string. So what I want to do is if ...
2
votes
3answers
51 views

Python regex string expansion

Suppose I have the following string: trend = '(A|B|C)_STRING' I want to expand this to: A_STRING B_STRING C_STRING The OR condition can be anywhere in the string. i.e STRING_(A|B)_STRING_(C|D) ...
3
votes
2answers
54 views

Convert a string list to a tuple in Python

I am trying to convert a string such as 'SUP E P I C' to a tuple containing all the non-spaced strings. For example, if the input is 'SUP E P I C', then the program should return ('S', 'U', 'P', 'E', ...
0
votes
2answers
26 views

Python RegEx help: Splitting string into numbers, characters and whitespace

I am trying to split my string into a list, separating by whitespace and characters but leaving numbers together. For example, the string: "1 2 +=" would end up as: ["1", " ", "2", " " ,"+", ...
0
votes
2answers
36 views

Creating a substitution cypher in Python

Hello fellow programmers :) Just a simple question Let's say I'm encrypting text. I have shadow characters for ”a, b, c, d, e” which are ”w, p, z, r, a” original =["a","b","c","d","e"] shadow = ...
-2
votes
0answers
44 views

Numbers Strings

So I have to write this program which has to basicaly read string long few lines. Here's an example of string paragraph I need to check: Let's say this is first line and let's check line 4 In this ...
0
votes
3answers
62 views

Numbers in string

So I have to write this program which has to basicaly read string long few lines. Here's an example of string I need to check: Let's say this is first line and let's check line 4 In this ...
0
votes
2answers
34 views

UnboundLocalError: local variable 'ext' referenced before assignment

I'm new to programming and Python--perfect storm... Despite being long, this is only a snippet of over 1300 lines of original code. What I'm adding is the ability to split filenames into root.ext ...
0
votes
2answers
67 views

How do I convert a string into a non string? [on hold]

how to convert a string to a non string in python? >>> bits=['0100','0011','1110','1001','0100'] >>> a=map(int,bits) >>> print a we have this as output [100, 11, 1110, ...
-3
votes
3answers
56 views

Check my string for numbers. Python [on hold]

So I'm writting program that should check my string for numbers and return only the first number in string (as int). Is there a method that checks strings for numbers? And if so, how can I make sure ...
1
vote
1answer
27 views

Confusion escaping single quotes in a single-quoted raw string literal

The following works as expected: >>> print re.sub('(\w)"(\W)', r"\1''\2", 'The "raw string literal" is a special case of a "string literal".') The "raw string literal'' is a special case of ...
0
votes
2answers
41 views

NameError in simple python code

This is a simple palindrome checker. The code works for numbers, but not strings. x = str(input("Enter a number: ")) if x == x[::-1]: print x + " is a palindrome!" else: print x + " is not a ...
1
vote
1answer
55 views

Python Substring replacement

i need to replace the substring in the main string mainstr='"Name":"xxx","age":"{"This":"has to","be":"replaced"}","dept":"cse"' substr='"{"This":"has to","be":"replaced"}"' Desired output: ...
-1
votes
1answer
29 views

Python Regex Find Pattern, Remove Rest of String, Write new String to File

I have the codez: import re pattern = ',' firstNames = "dictionary//first_names.txt" new_file = [] def openTxtFile(txtFile): file = open (txtFile,"r") data = file.read() print (data) ...
2
votes
1answer
34 views

Python complicated regex string expansion

Suppose I have a string of the following form: ABCDEF_(0-100;1)(A|B)_GHIJ_(A-F) I want to be able to expand this to: ABCDEF_0A_GHIJ_A ABCDEF_1A_GHIJ_A ABCDEF_2A_GHIJ_A ... ABCDEF_100A_GHIJ_A ...
2
votes
2answers
51 views

Combine strings, extract substrings

(I'm using python) I'm working with a large file of RNA sequences, and I'm trying to reformat it to use in a clustering program. My file is made up of two types of 'lines.' 1) Accession numbers for ...
2
votes
1answer
25 views

Python: how to make it not change line

There's a file with various names on it, each name as /n at the end of it so when I open the file in python it prints each name in a different line The problem is I have to print 2 names on each ...
-2
votes
4answers
50 views

How to convert a string to a float?

I'm currently working on a program in Python and I need to figure out how to convert a string value to a float value. The program will ask the user to enter a number, and uses a loop to continue ...
1
vote
1answer
46 views

How to recursively join lists in python?

I have a list which contains lists, like this: l = ['celery', 'beef', ['apples', 'oranges', 'bananas']] And I want to join them with different characters depending on whether they are in the list ...
-3
votes
2answers
59 views

Converting string list into integer list beginning from 1 [duplicate]

I want to know a method to convert a list of strings such as: myList = ["Bob1", "Bob2", "Bob3", "Bob4"] Somehow into integers so that they are 0, 1, 2, 3 And then so that they are 1, 2, 3, 4 and then ...
0
votes
1answer
42 views

Python unicode force convert to ascii (str)

when using post in django, a ascii string will be automatic transfer into unicode string. for example: s = '\xe2\x80\x99' is a str type string. (Which is utf-8 format) when post this string to ...
0
votes
0answers
15 views

Ahocorasick search tree return index out of bound

I used the python package ahocorasick(https://hkn.eecs.berkeley.edu/~dyoo/python/ahocorasick/) for text matching for the state name here: import ahocorasick states = { 'AK': 'Alaska', 'AL': ...
7
votes
5answers
126 views

python counting number of presence and absence of substrings in list of sequences

you can get the data here! 2shared the bottom download I'm analyzing biological data with python. I've written down a code to find matching substrings within a list of lists of long strings. The ...
1
vote
1answer
37 views

use str.format() in django logging

I use django 1.6 and python 3.2 in Ubuntu 12.04.And i find django logging is using the python's built-in logging module.As the dictConfig format(python 3.x version) said, I can use 3 kind format style ...
0
votes
3answers
61 views

recursive algorithm string match

I recive 2 strings. I have to implement a recursive function that return the best option for them to be similar by adding -. I give an exemple cause this is not good description str1="sdfsdf" ...
1
vote
3answers
43 views

Multi-line dictionaries: Replace the key as per a word in value

I have a dictionary in which I have to replace all the keys depending on a word in the value set. So my dictionary is: { 23: {'score': -8.639, 'char': False, 'word': 'positive'} } { 56: ...
1
vote
1answer
43 views

Using arithmetic operators with a variable holding a list

I am quite confused on this, so I hope someone can help me. So what I have is basically a list in Python, then I have set a variable which within I have used the list name and called the first ...
6
votes
5answers
116 views

Is using `str` the correct idiom for working with digits in Python

I understand that one way to work with the digits of a number in Python is to convert the number to a string, and then use string methods to slice the resulting "number" into groups of "digits". For ...
1
vote
1answer
52 views

python's .replace leaves empty lines

I'm using scrapy to pull data from a website. The unadulterated version comes like this: {eps: 25} {eps:[]} {eps:[]} {eps:[]} {eps: 50} {eps:[]} {eps:[]} {eps:[]} Now I am not sure why the blank ...
-2
votes
2answers
40 views

defineing a function easyCrypto() [on hold]

I am asked to define a function easyCryto . It takes a string as an input and prints an encryption. Every character at an odd position i in the alphabet will be encrypted with the character at ...
-2
votes
2answers
36 views

Python - issue comparing a string that I get from the command line using argparse

I'm having a strange issue with a string compare that seems to stem from my use of the argparse module to get a value from the command line. Basically the goal is to take in a number the name of a ...
0
votes
2answers
71 views

Dealing with Missing Data within a String [on hold]

Suppose that I have a long string, S, that looks like: S = "A, 2001, 2003, 2005, A, 2002, A, 2003, 2004, 2005, 2006, A, 2001, 2002, A, 2001, 2006, 2004, A..." Using Python, how does one obtain the ...
2
votes
3answers
58 views

Django, Detecting if variable is a number

In a function in Django, the user can send me a number or a string, and I want to know if I received a number or a String (Tip: The number will always be an integer between 1-6) I want to know if ...
-1
votes
2answers
25 views

manipulating strings in a list [on hold]

im just in a beginner cmpt course for python and just learning about lists. One of our questions is to make a function that will recieve something like this(may have more than just 2 values) ...
2
votes
1answer
60 views

most frequent substrings with tolerance

I am trying to find the most frequent substrings (of a certain lenght L) on a string, but allowing a certain threshold or error T (in amy position of the substrings), obviously not longer than L ...
1
vote
2answers
28 views

position of approximate matches

I am working on a script able to make an approximate match of a certain pattern in a string, reporting just the positions in which these patterns (they could be overlapping) initiate. So far, I ...
1
vote
2answers
43 views

sub-substrings present x times in at least one substring of a string in python

I am trying to find the sub-substring(s) with certain frequency in a list a substrings (i.e.windows) of a larger string in python. It is, the goal is to find what sub-substrings (of a fixed length) ...
2
votes
1answer
21 views

Tkinter StringVar error

Hi i get an error with this code that StringVar() is not defined, and its probably a small thing but i am not that experienced with tkinter and would like some help, thanks. Here's my code: import ...
-2
votes
2answers
37 views

How to convert strings to regular expressions in python? [closed]

I get some strings passed from command line arguments in my python script and want to use these strings as regular expressions. How to do?
0
votes
3answers
48 views

Python : How to check a string for a special character

I can only use a string in my program if it contains no special characters except underscore _. How can I check this? I tried using unicodedata library. But the special characters just got replaced ...
-4
votes
2answers
103 views

Could someone help me with Hangman?

I know my code is pretty bad (I'm a beginner!), but I'm having trouble with the print_blanks function. When the user enters a correct letter, it doesn't show the letter in the word, it just shows the ...
0
votes
2answers
75 views

Python:Comparing all list items to substring of string

All the items in the list should be compared to the every 50 long substring of a string. The code i have written is working smaller string lengths but if string is very large(eg:8800) its not...Can ...
0
votes
3answers
42 views

How to make text from user input start a new line at every space?

Essentially I want each new word from the user input to be on the next line, so a sentence such as: "Hello World" would appear as "Hello" "World" Here is my current script: EnterString = ...
-10
votes
1answer
65 views

What does python print and why? [closed]

dlist ="sunday:sn; monday:mn; tuesday:tus; wednsday:wed; thursday:thur; friday:fr; saturday:st" days= dlist.split(";") print (len(days), days[4]) What is it supposed to print and why? ...
1
vote
3answers
63 views

Can you compare strings in python like in Java with .equals?

Can you compare strings in Python in any other way apart from ==? Is there anything like .equals in Java?

15 30 50 per page