Questions tagged [strip]

"strip" refers to the process of removing (stripping) certain characters from a string. A common example is removing trailing whitespace characters.

1330 questions
-1
votes
4 answers

strip() does not replace all \n

I'm trying to remove all "\n" in this string. However the string.strip() method does not entirely clean the text body = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nSome text\n\nHow toremovealln?\n\t\t\t\t\tbecause…
J. Doe
  • 3,458
  • 2
  • 24
  • 42
-1
votes
2 answers

String tags and rearranging order from output

how would I go about stripping away the " - and tags from the curl output below? i tried strip_tags but then I do not know how to rearrange the order
acctman
  • 4,229
  • 30
  • 98
  • 142
-1
votes
4 answers

Python strip and Counter for top 3 alphabets

The output should be top 3 letters from the given input, but I am unable to remove the whitespace even after using strip function over the input. Code : from collections import Counter insider = input("Enter the input you wanna enter : ") …
Abhiram Satputé
  • 604
  • 1
  • 5
  • 21
-1
votes
3 answers

Python strip() and readlines()

I have a code that I am trying to run which will compare a value from a csv file to a threshold that I have set within the py file. My csv file has an output similar to below, but with 1030 lines -46.62 -47.42 -47.36 -47.27 -47.36 …
user7524882
  • 1
  • 1
  • 5
-1
votes
4 answers

Regarding stripping the commas, colons in the list of numbers

I have a list of numbers in a file after binning the values to the nearest integers by using the dict,and Counter functions... from collections import Counter count_numbers=dict(Counter([round(x) for x in list_numbers]) and the values i got…
D.H.N
  • 69
  • 1
  • 9
-1
votes
1 answer

how to strip a txt file of multiple things?

I am creating a function which reads data of a txt file, the text file is set up as one sentence per line. I have 6 requirements to strip the file of to make it usable later on in my program: 1. Make everything lowercase 2. Split the line into…
Nathannn
  • 23
  • 6
-1
votes
3 answers

remove middle octets from an ip until some criteria is met

I have a string of IP and port numbers which is like : "10.213.110.49.33482;10.213.106.12.20001:" The two ip's are separated by a semi-colon. Last decimal shows port number.What I need is to convert the above string which would look…
Prashant Kumar
  • 2,057
  • 2
  • 9
  • 22
-1
votes
2 answers

Why split and strip gives different output in python?

I was trying to extract the state name from the string 'Rhode Island[edit]'. When I tried .split('[[]').str[0], I was given the correct result 'Rhode Island'. However, when I tried .rstrip('[edit]'), I was given the wrong result 'Rhode Islan'. I got…
Puzhou
  • 3
  • 2
-1
votes
3 answers

Splitting up a list into a 2D list using tabs and spaces

I am trying to split up a python list into a 2D list starting with the following testList = ["Color Blue»Temperature Warm»Gender Male", "Color Green»Temperature Warm»Gender Female"] Where » is a tab character and the attributes (color,…
Alan
  • 1
  • 1
  • 3
-1
votes
2 answers

Remove \n from python string

I have scraped a webpage using beautiful soup. I'm trying to get rid of a '\n' character which isnt eliminated despite whatever I try. My effort so far: wr=str(loc[i-1]).strip() wr=wr.replace(r"\[|'u|\\n","") print(wr) Output: [u'\nWong; Voon…
FlyingAura
  • 1,541
  • 5
  • 26
  • 41
-1
votes
1 answer

What is the mechanism behind strip() function followed by a slice notation in python?

For example sentence = "hello world" stripped1 = sentence.strip()[:4] stripped2 = sentence.strip()[3:8] print (stripped1) print (stripped2) Output: hell lo worl Here strip( ) is a function object. So it should either take parameters or be followed…
Uchiha Madara
  • 984
  • 5
  • 16
  • 35
-1
votes
2 answers

Scraping needs to stop when it sees a white row

from bs4 import BeautifulSoup import urllib import json import os jaren = [str("2012"), str("2010"), str("2006"), str("2003"),str("2002"), str("1998"), str("1994"), str("1989"), str("1986"), str("1982"), str("1981"), str("1977"), str("1972"),…
Danisk
  • 113
  • 1
  • 1
  • 9
-1
votes
1 answer

Removing numbers.

Im trying to remove numbers from a print statement, but when i do try, it doesn't. It actually adds extra lines that are unwanted. p=open('test1.txt','r') t=open('outChanger.txt','w') counter=0 for l in p: counter+=1 if counter%3==0: …
Mell0w
  • 47
  • 7
-1
votes
3 answers

Stripping numbers dates until first alphabet is found from string

I am trying an efficient way to strip numbers dates or any other characters present in a string until the first alphabet is found from the end. string - '12.abd23yahoo 04/44 231' Output - '12.abd23yahoo' line_inp = "12.abd23yahoo 04/44 231" line_out…
yatri
  • 33
  • 6
-1
votes
1 answer

Python - split a string with regular expression results and strip it

I need to write a function that will take a string as an argument and gives the description of the string as output. So when i insert the following string in my function: "12:30 – 13:00 Red Light Radio – Ovational Exercises" The output…