Linked Questions
19 questions linked to/from Is there a generator version of `string.split()` in Python?
5
votes
1
answer
1k
views
Is there a lazy/iterator equivalent to `str.split()`? [duplicate]
Possible Duplicate:
Is there a generator version of string.split() in Python?
str.split(delim) splits a string into a list of tokens, separated by delim. The entire list of tokens is returned in ...
152
votes
7
answers
204k
views
Iterate over the lines of a string
I have a multi-line string defined like this:
foo = """
this is
a multi-line string.
"""
This string we used as test-input for a parser I am writing. The parser-function receives a file-object as ...
34
votes
7
answers
22k
views
Splitting a string into an iterator
Does python have a build-in (meaning in the standard libraries) to do a split on strings that produces an iterator rather than a list? I have in mind working on very long strings and not needing to ...
13
votes
10
answers
32k
views
Python: how to determine if a list of words exist in a string
Given a list ["one", "two", "three"], how to determine if each word exist in a specified string?
The word list is pretty short (in my case less than 20 words), but the strings to be searched is ...
22
votes
3
answers
6k
views
slices to immutable strings by reference and not copy
If you use string.split() on a Python string, it returns a list of strings. These substrings that have been split-out are copies of their part of the parent string.
Is it possible to instead get ...
9
votes
4
answers
15k
views
efficient way to get words before and after substring in text (python)
I'm using regex to find occurrences of string patterns in a body of text. Once I find that the string pattern occurs, I want to get x words before and after the string as well (x could be as small as ...
1
vote
1
answer
3k
views
How to get unique words from a list quickly?
I have a file with 3 million sentences (approx). Each sentence has around 60 words. I want to combine all the words and find unique words from them.
I tried the following code:
final_list = list()
...
-1
votes
3
answers
3k
views
How can I go to the next line in .txt file?
How can I read only first symbol in each line with out reading all line, using python?
For example, if I have file like:
apple
pear
watermelon
In each iteration I must store only one (the first) ...
1
vote
2
answers
3k
views
Using Python's multiprocessing to calculate the sum of integers from one long input line
I want to use Python's multiprocessing module for the following:
Map an input line to a list of integers and calculate the sum of this list.
The input line is initially a string where the items to be ...
0
votes
3
answers
1k
views
How to fill a list in a single line with n integers?
I want to fill a list with n integers in a single line, I tried this but how to add a limit of n?
L=[int(x) for x in input().split()]
3
votes
4
answers
108
views
Is an intermediate list necessary in a multi-level list comprehension
Here is a specific example:
my_dict={k:int(encoded_value)
for (k,encoded_value) in
[encoded_key_value.split('=') for encoded_key_value in
...
0
votes
2
answers
350
views
How do I build a tokenizing regex based iterator in python
I'm basing this question on an answer I gave to this other SO question, which was my specific attempt at a tokenizing regex based iterator using more_itertools's pairwise iterator recipe.
Following ...
0
votes
1
answer
213
views
Loading a string into numpy record array
I have a string formatted that looks like
contents = "1,2,3;\n4,5,6;"
Which I want to load into numpy record array with dtype
structure = {'names': ['foo', 'bar', 'baz'], 'formats': ['i4']*3}
To ...
3
votes
1
answer
148
views
Does a list_iterator garbage collect its consumed values?
Suppose I have li = iter([1,2,3,4]).
Will the garbage collector drop the references to inaccessible element when I do next(li).
And what about deque, will elements in di = iter(deque([1,2,3,4])) be ...
0
votes
3
answers
139
views
to change a text file containing multiline strings
I have a text file consisting of multiline (hundreds of lines actually) strings. Each of the strings starts with '&' sign. I want to change my text file in a way that only the first 300 characters ...