Python implements three methods to process one character each time, and python three methods
This example describes three methods for python to process a single character each time. Share it with you for your reference.
The specific method is as follows:
a_string = "abccdea" print 'the first' for c in a_string: print ord(c)+1 print "the second" result = [ord(c)+1 for c in a_string] print result print "the thrid" def do_something(c): return ord(c)+1 result = map(do_something ,a_string) print result
The output is as follows:
the first 98 99 100 100 101 102 98 the second [98, 99, 100, 100, 101, 102, 98] the thrid [98, 99, 100, 100, 101, 102, 98]
I hope this article will help you with Python programming.
Python handles string processing issues in files:
The answer for the upstairs is changed to the first line.
F1 = open('1.txt ')
No other problems
However, there is a simpler way:
F1 = open('1.txt ')
Linen = 1
For line in reader:
If not line. find ('44. 2% ') =-1:
Print linen
Linen + = 1
F1.close ()
If it is helpful to you, please remember to adopt a satisfactory answer. Thank you! Wish you a happy life!
How does python retrieve a string from a file?
If the file is not large
Import re
F = open ('xxxx. xx', 'R'). read ()
FList = re. split (R' \ s + ', f)
OK. All of them are included in the fList list.