Skip to main content

All Questions

Tagged with
0 votes
0 answers
11 views

Parsing expression with python: from string to integers [duplicate]

I was trying to split this string in two numbers using multiple delimeters and re library in python Input: "['2 5']" Output [2,5] Code: data = re.split(r"'[ ]'",str(sys.stdin....
Sara's user avatar
  • 1
0 votes
3 answers
701 views

Invalid syntax error of Python 3's str.split in Python 2

The below line works fine for me in python3. How can I fix it for python 2. word, *vector = line.split() Error in Python 2: word, *vector = line.split() ^ SyntaxError: invalid syntax
joydeba's user avatar
  • 1,265
1 vote
4 answers
282 views

Tricky way to split string by \t

String like that: x = dir\tsubdir1\t\tfile1.ext\t\tsubsubdir1\tsubdir2\t\tsubsubdir2\t\t\tfile2.ext How to 'pythonish/tricky' split above string into list? dir \tsubdir1 \t\tfile1.ext \t\tsubsubdir1 ...
andrew's user avatar
  • 3,151
0 votes
2 answers
68 views

How to remove marks from string and turn it into a list

I need to create a function that turns the string to a list without !?., %#$ . and without capital letters. The string at the end is just an example so it needs to return ['mr', 'stark', 'i', "don't", ...
sereen masalha's user avatar
0 votes
3 answers
438 views

Python: How to move the position of an output variable using the split() method

This is my first SO post, so go easy! I have a script that counts how many matches occur in a string named postIdent for the substring ff. Based on this it then iterates over postIdent and extracts ...
AWSnell's user avatar
0 votes
0 answers
25 views

How to divide text into several parts relative to one character

How to separate text from "^" to "^" and save data to different variables Below I insert what is the main problem: DM^126287^8209/2018^INLMDU 39942^70 It will often be the case that the number of ...
MarcinB's user avatar
  • 17
1 vote
3 answers
1k views

Split text file Python

I am working on text files like this: Chapter 01 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt Chapter 02 consectetur adipiscing sed do eiusmod tempor ...
Sergei Leduc's user avatar
2 votes
3 answers
4k views

Remove word from string start with specific characters

I have the following string: my_string = "This is an example string, ex , excatly , index , hyperextension" I want to remove all words that start with ex in Python. So the result I want would be: ...
lothlorientos's user avatar
1 vote
5 answers
81 views

Need to create an array of arrays for each string

So I have data that looks something like this: >> print data "12345","string1","string2","string3","string4","string5" "67890","string6","string7","string8","string9","string10" I want to be ...
A.Roger's user avatar
  • 13
0 votes
1 answer
971 views

Cannot Get Python to Recognize Escape Tab Character

I'm new to Python and am having trouble with a seemingly simple objective. I've tried several methods for splitting a string by a tab character to no avail. testStr = 'word1 word2' values = ...
W.Harr's user avatar
  • 303
1 vote
1 answer
30 views

Spiting the pandas data frame value into two columns

I have a pandas data frame in which I have to split the product id as shown below: || _id || || ProductId-2118-product-chefs-signature-is-our-go-to-kebab || ||_id || text || || ProductId-2118 ||...
jack andrew's user avatar
8 votes
1 answer
17k views

Extract first 3 words from string

I am looking for a script code to search for the first 3 words of a string. Example : words = 'I am confused looking for 3 words from the front' Expected results: 'I am confused'
Tarjo's user avatar
  • 579
3 votes
4 answers
756 views

Trim string (both left and right) to nearest word or sentence

I'm writing a function that finds a string near a identical string(s) in a larger piece of text. So far so good, just not pretty. I'm having trouble trimming the resulting string to the nearest ...
Ghoul Fool's user avatar
  • 6,987
3 votes
6 answers
689 views

How to extract a part of a string

I have this string: -1007.88670550662*p**(-1.0) + 67293.8347365694*p**(-0.416543501823503) but actually I have a lot of string like this: a*p**(-1.0) + b*p**(c) where a,b and c are double. And I ...
Guy Davis's user avatar
3 votes
4 answers
887 views

How to recognize single digit in string to insert leading zero?

In Python, I have a string with either two digits or one digit: 8 5E 9C 52 30 0 In every one digit in the string, I would like to add a leading zero to it (e.g. convert 5 to 05) and make it two ...
Jo Ko's user avatar
  • 7,575

15 30 50 per page