python - Add empty elements to a list -
phrase = "test phrase" progress = [] letter in phrase: if letter != none: progress.append("-") else: progress.append("") print progress
so want give me ["-","-","-","-","","-","-","-","-","-"] can string.join them , ---- ----- hidden string. ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-'] i'm getting. no empty element mark space.
use != ' '
, append(" ")
phrase = "test phrase" progress = [] letter in phrase: if letter != ' ': progress.append("-") else: progress.append(" ") print ''.join( progress ) #---- ------
python
No comments:
Post a Comment