1
vote
2answers
27 views

Title case for a paragraph

I'm creating a markov chain algorithm. I output a variable called sentences which contains one string of sentences. I want to make the sentences sentence case so I wrote this: for l in range(0, ...
0
votes
2answers
51 views

python 3 - find and replace all numbers in a text file

I realise that finding and replacing in a text file has already been asked, but I wasn't sure how to apply it to my situation. Basically, this goes on earlier in the program: while True: ...
2
votes
4answers
67 views

Pythonic way to split a line into groups of four words?

Suppose I have string that look like the following, of varying length, but with the number of "words" always equal to multiple of 4. 9c 75 5a 62 32 3b 3a fe 40 14 46 1c 6e d5 24 de c6 11 17 cc 3d d7 ...
-1
votes
0answers
41 views

python summarize numbers in string [closed]

I have a list of integers, say: lst = [1,2,3,8,11,12,13,16,19,20,24] I want to use this list to create an output string as: 'The following elements are in lst: 1-3, 8, 11-13, 16, 19, 20, 24.' ...
0
votes
1answer
36 views

Converting a list of “stuff” to a single string

This is a pretty basic question, but I have looked in three tutes and can't find an answer. I have a bunch of "items": "The value is ", 54, and ". Do you agree?" where 54 is an integer, not a ...
0
votes
2answers
55 views

Testing string for characters that are not letters or numbers [duplicate]

I have a string like 'H897b Site', and I want to test that string to make sure it only contains letters and numbers and no special characters. So in cases like 'H897b Sit$e' and 'H8(&b Site' I ...
1
vote
1answer
35 views

Pandas read_csv dtype leading zeros

So I'm reading in a station codes csv file from NOAA which looks like this: "USAF","WBAN","STATION NAME","CTRY","FIPS","STATE","CALL","LAT","LON","ELEV(.1M)","BEGIN","END" ...
3
votes
1answer
187 views

split strings and save comma int python

I have the following string c='a,b,c,"d,e",f,g' and I want to get b=['a','b','c','d,e','f','g'] so b[3]=='d,e' any ideas? the problem with c.split(',') is that it splits also 'd,e' ...
11
votes
3answers
11k views

Python: TypeError: cannot concatenate 'str' and 'int' objects

I am trying to run this simple program which adds 2 strings together than adds those strings as integers, I don't understand why my code doesn't work well here it is a = raw_input("Enter a: ") b = ...
4
votes
6answers
7k views

Python code to remove HTML tags from a string

I have a text like this: text = """<div> <h1>Title</h1> <p>A long text........ </p> <a href=""> a link </a> </div>""" using pure Python, with no ...
21
votes
1answer
13k views

Best way to convert string to bytes in Python 3?

There appears to be two different ways to convert a string to bytes, as seen in the answers to TypeError: 'str' does not support the buffer interface Which of these methods would be better or ...
93
votes
2answers
82k views

How to convert string to lowercase in Python?

Is there any way to convert an entire user inputed string from uppercase, or even part uppercase to lowercase? eg. Kilometers --> kilometers. I am writing a program that doesn't work when any sort of ...
52
votes
4answers
6k views

How can I print a literal “{}” characters in python string and also use .format on it?

x = " \{ Hello \} {0} " print x.format(42) gives me : Key Error: Hello\ I want to print the output: {Hello} 42
40
votes
5answers
35k views

Python: Split string with multiple delimiters

I found some answers online, but I have no experience with regular expressions, which I believe is what is needed here. I have a string that needs to be split by either a ';' or ', ' That is, it has ...
54
votes
7answers
67k views

Printing without newline (print 'a',) prints a space, how to remove?

I have this code: >>> for i in xrange(20): ... print 'a', ... a a a a a a a a a a a a a a a a a a a a I want to output 'a', without ' ' like this: aaaaaaaaaaaaaaaaaaaa Is it ...

1 2 3 4 5 244
15 30 50 per page