2
votes
1answer
57 views

Tough List Comprehension Split Letters and Numbers

So, another challenge from my professor. I've finished it, but wanted to get some feedback, and see how other people might work this problem. Assume you have a string, such as "Hello 34215 World ...
2
votes
0answers
11 views

Parsing time ranges with PyParsing

The following code is intended to parse a string of the following format and return whether the current time falls in that window: ...
4
votes
1answer
53 views

Permutations program in Python

This code asks for letters and a number of letters per word and generates all possible permutations. Then compares those permutations with an English dictionary and creates a list with all the words ...
2
votes
1answer
36 views

More Pythonic version of finding substring with one glob-like expression

Giving the following example list the task is: find out whether the second expression is in the first one. * shall be considered as a wildcard for any ...
4
votes
2answers
255 views

Manipulating filenames using Python

I was tasked with creating a script to be able to rename some files and then move them into different folders based on a code in the filename. ...
2
votes
2answers
74 views

Word counter script

I made a word counter. It works as long as there aren't any lone punctuation marks. How could it be improved? (Could it be made simpler? Are the comments detailed/clear enough? etc.) I know it's ...
5
votes
2answers
126 views

Z-Algorithm for pattern matching in strings

I was trying to refactor the following Python code (keeping the same time-complexity) which is an implementation of Z-Algorithm for pattern matching in strings. ...
4
votes
2answers
49 views

Efficient use of regular expression and string manipulation

The following is my solution to Java vs C++. I think the way I have used the re library is inefficient, and possible erroneous as I am getting tle. ...
4
votes
1answer
33 views

Refactor Oxford Comma function (and other functions)

I wrote a program that managed projects and created a set of SQL files for each project. In the logic, I have a few functions that, each time I look at them, I wonder if they could be written in a ...
2
votes
3answers
48 views

Speeding up Project Euler 43 - sub-string divisibility

The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property. ...
2
votes
2answers
43 views

Simple evolutionary string matching

This is based on a very similar question I asked, found here. The intent of this program is to start with a set number of random strings of zeros and ones, and eventually evolve them to find one ...
4
votes
2answers
48 views

Readability in creation of a long output string

Below is a function from a driver that I wrote for and I2C temperature sensor. The function takes as input the name of the bus and the device's bus address, reads it's status register, and then ...
1
vote
2answers
44 views

How can I optimize this string function so that it could work on very large strings?

I want to build a function which finds the longest substring that is common between two large strings, I want to do this using the first two functions. I'm running it on very large strings (containing ...
0
votes
2answers
65 views

Increase efficiency of basic string compressor

I was wondering what I can do to increase the performance of this program. The algorithm is pretty slow right now but I was wondering what I can do to increase the efficiency of this program. I used ...
2
votes
3answers
70 views

How can I optimize this hash string function?

I'm writing a function which gets two strings and a number k as an input, and outputs a string with length k which is present in ...
7
votes
2answers
206 views

Given a page of content, determine shortest snippet containing all search phrases (no order required)

A recruiter gave me a homework problem as a part of the recruiting process and after receiving my submission he told me that he decided not to proceed with me. When I asked for the reason, he told me ...
5
votes
2answers
181 views

Is this a good implementation of the split function?

I have this implementation of the split algorithm that different from .split() method you can use with multiple delimiters. Is this a good way of implementing it ...
7
votes
3answers
384 views

Better way to create a string of random characters

I'm generating domains with random names but I'm pretty new to Python. I used the map function because it packages the results into a list which I can then join() ...
4
votes
1answer
53 views

Increase performance of Boyer Moore

Here is my Boyer Moore code in Python: ...
7
votes
1answer
58 views

Making line by line replacements using values from multiple arrays

I currently have a Python script that parses a file (in this case an XML file) and makes line by line replacements as necessary, depending on the values of multiple arrays. As it stands now the script ...
2
votes
2answers
111 views

Speeding up and fixing phone numbers from CSVs with Regex

I've hodgepodged together an attempt to extract all phone numbers from all CSVs in a directory, regardless of where they are and what format they're in. I want all phone numbers to be printed to a ...
4
votes
3answers
371 views

Can this list comprehension be made more pythonic?

Quite a specific question can the below code be made more clearer / pythonic in any way. Essentially based on the condition of the string x((len(x) / 3) - 1), I ...
8
votes
3answers
117 views

Longest 'balanced' substring

I was given a task where given a string of '0's and '1's, return the longest substring where the count of '0's and '1's are equal. I was told also that the code should be O(n) and space O(1). Below ...
0
votes
1answer
46 views

Dealing with a dirty table

I have to deal with a really ugly looking response I get back from a particular device. The string represents a table. Each section of the string represents the form: ...
2
votes
2answers
87 views

Numbers to Text Program - Python Training

I have written a numbers to text challenge for some people in my organisation to practice their Python skills. I am an economist working with pandas, but I am trying to teach them some stuff about ...
7
votes
1answer
106 views

Python compress and send

The following two functions are used to compress arbitrary Python objects and send them safely via socket or email, using only printable chars. In my specific message protocol, '=' signs are also not ...
4
votes
1answer
76 views

Cutting strings into smaller ones based on specific criteria

So, I've got this largish (for me) script, and I want to see if anybody could tell me if there are any ways to improve it, both in terms of speed, amount of code and the quality of the code. I still ...
9
votes
2answers
97 views

Is there a simpler way to make an English-readable list from strings in a tuple?

I looking over some old code, I had written the function below with a C-style for-loop iterating over a count variable. I then fixed it up with new knowledge, but still am suspicious that there is ...
4
votes
1answer
95 views

How to make this lingo game more compact?

I made a lingo game using Python: You guess a word, and if its letter(s) is in the same spot as a hidden word's, you add [] around the letter. If it's in the hidden word, but not in the same spot, ...
5
votes
1answer
178 views

Trying multiple regexes against a single string

I have a huge list of regexes (>1,000 but <1,000,000) that I want to test against (many) single strings. It is unlikely and unintended that more than one such expression would match a single ...
8
votes
3answers
145 views

Printing a week range string in Python

For some reporting, I need to print a human readable date string for the week covered by the report, using just the standard python module library. So the strings should look like: Dec 29, 2013 - ...
2
votes
1answer
927 views

String Matching and Clustering

I have a pretty simple problem. A large set of unique strings that are to various degrees not clean, and in reality they in fact represent the same underlying reality. They are not person names, but ...
3
votes
2answers
390 views

Successful Encoder and Decoder for messages

I recently wrote a code for a encoder and decoder that works off of a key and the only way to decode the message is with this program and the case-sensitive key. I have yet to incorporate punctuation ...
0
votes
1answer
78 views

Please critique my Python remove_prefix and remove_suffix functions

If the prefix/suffix does not match the beginning or the end of a string, then, depending on how I call these functions, they should either raise an exception or return the original text unmodified. ...
2
votes
4answers
2k views

Improving efficiency for finding longest contiguous non-decreasing substring

I was working on a problem set and I came across this problem: Assume s is a string of lower case characters. Write a program that prints the longest ...
1
vote
2answers
101 views

Conditional concatenation

I want to do a conditional concatenation. My issue is at the end of the for-loop. I have all variables starting with \n for removing this, and I need to strip out ...
0
votes
0answers
41 views

Optimize Python string handling [duplicate]

How can I better optimize this check? It looks very lengthy. ...
6
votes
5answers
407 views

How can I optimize this array operation for speed?

I've been trying to take image pixel data and write it out into printer code and my results are rather slow. Here is a asimplified version of what I have so far (image is a PIL Image object of 1200 x ...
1
vote
1answer
302 views

Automatically indent a whole block of text into str.format

I wondered if there was any better way of doing so. I had a hard time figuring it out (it seemed nobody else already tried to do so). ...
1
vote
1answer
73 views

Python abilities on strings

the Encoding scheme is given below: Don't replace the characters in the even places. Replace the characters in the odd places by their place numbers . and if they exceed 'z', then again they ...
3
votes
2answers
3k views

Counting letters in a string: Python optimisation

This little program is self-explanatory. I count letters in a string (can be any string), using a for loop to iterate through each letter. The problem is that this ...
2
votes
1answer
1k views

Get metadata from an Icecast radio stream

I am new to Python and not very familiar with advanced Python data structures. I have written a function to receive data from a socket in Python and perform string manipulations on it. The basic ...
3
votes
4answers
173 views

String parsing with multiple delimeters

My data is in this format: 龍舟 龙舟 [long2 zhou1] /dragon boat/imperial boat/\n And I want to return: ...
3
votes
1answer
1k views

Python 3: Finding common patterns in pairs of strings

I have written a piece of code that finds common patterns in two strings. These patterns have to be in the same order, so for example "I am a person" and "A person I am" would only match "person". The ...
2
votes
3answers
57 views

Flexible multiple string comparision to determine variable value

I've a web form that allows users to create clusters of three sizes: small, medium and large. The form is sending a string of small, medium or large to a message queue, were job dispatcher determines ...
4
votes
1answer
475 views

Nicely tabulate a list of strings for printing

I have a list of strings of variable lengths, and I want to pretty-print them so they are lining up in columns. I have the following code, which works as I want it to currently, but I feel it is a ...
1
vote
1answer
82 views

Reversi text board parsing to bitfield

This Python code parses string representations of Reversi boards and converts them into bit string suitable for use by a bitstring module: b = BitArray('0b110') or ...
6
votes
2answers
631 views

Word frequency generator in Python

Please critique my word frequency generator. I am a beginner programmer so any criticism are welcome. Original Code: http://pastebin.com/rSRfbnCt Here is my revised code after the feedback: ...
5
votes
1answer
614 views

Memory issues with Find Strings Problem on InterviewStreet

Here is the code I wrote for the problem at http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4efa210eb70ac where we need to to print the substring at a particular index from ...