Converting a string to a list with sorting in lexicographic order
📁 List, string, Advanced Python Topics
How to convert a string consisting of words separated by spaces into a list, and sort the resulting list in lexicographic order?
Given a string of words separated by spaces:
s = 'abc a bCd bC AbC BC BCD bcd ABC'convert it to a list, with the separator "space":
a = s.split(' ')we get:
['abc', 'a', 'bCd', 'bC', 'AbC', 'BC', 'BCD', 'bcd', 'ABC'] A file is simply a sequence of bytes, among which there are line breaks. That is, if you are working with a file:
line 1line 2line 3...then in reality the disk contains a sequence of bytes:
line 1␊line 2␊line 3You can, without recalculating/rewriting the entire file, both inside a line and between lines, for example:
line 1␊XXXXXXXXXXXline 3then, when viewing the file line by line, you will see:
Log in to leave an answer