I am comparing 2 textile files in the Linux system which is the ls -r directory Is of I compare 2 files using difflib.differ and found this list as my result (I put dots to keep the list here short):
'Code: \ n', 'arcasail \ n', 'HOSTNAME \ n', 'rmcpujar \ n', ..., 'cliener \ n', '+ additional file \ n', ' Rc.d \ n '' + ExtraFile2 \ n ', ...,' resolv.conf \ n ',' wu-ftpd \ n ']
'+' Sign out to do something else How do I manipulate the list? In the above example, I want to be able to get this string "extraFile" and "extraFile2"
Thanks to all those who have posted solutions It helps a lot and I am grateful :)
I want to do some string here:
newresult = [file [2: -1] for the resulting file
I print file.startswith ('+')]
in the range (for LAN (new-constellation)): i print newresult [i]
< P> thanks ~ !!! :
You can use the list comprehension:
newlist = [File as a result of file [1:] If file.startswith ('+')] # ^ - initially get rid of `+`
And if you want to get rid of only new characters and white space:
newlist = [file [1:]. File.startswith ('+')] will use another method for the result in the Strip () file, but you can not manipulate the string again ( Just want to mention it for completeness):
newlist = filter (lambda s: s.startswith ('+', result)
Comments
Post a Comment