Linked Questions

5 votes
1 answer
1k views

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 ...
Li-aung Yip's user avatar
  • 12.5k
152 votes
7 answers
204k views

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 ...
Björn Pollex's user avatar
34 votes
7 answers
22k views

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 ...
pythonic metaphor's user avatar
13 votes
10 answers
32k views

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 ...
yegle's user avatar
  • 5,875
22 votes
3 answers
6k views

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 ...
Will's user avatar
  • 76k
9 votes
4 answers
15k views

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 ...
user1253952's user avatar
  • 1,597
1 vote
1 answer
3k views

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() ...
Bharath  kumar k's user avatar
-1 votes
3 answers
3k views

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) ...
deethereal's user avatar
1 vote
2 answers
3k views

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 ...
user avatar
0 votes
3 answers
1k views

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()]
Houssem Hkiri's user avatar
3 votes
4 answers
108 views

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 ...
Michael Goldshteyn's user avatar
0 votes
2 answers
350 views

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 ...
Veltzer Doron's user avatar
0 votes
1 answer
213 views

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 ...
bountiful's user avatar
  • 804
3 votes
1 answer
148 views

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 ...
Benoît P's user avatar
  • 3,270
0 votes
3 answers
139 views

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 ...
ammad aslam's user avatar

15 30 50 per page