Determine if a string is collapsible: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|REXX}}: Marked incomplete as per task author) |
(→{{header|Phix}}: Add Python) |
||
Line 444: | Line 444: | ||
length 17 output: <<< - Hary S Truman >>> |
length 17 output: <<< - Hary S Truman >>> |
||
</pre> |
</pre> |
||
=={{header|Python}}== |
|||
<lang python>from itertools import groupby |
|||
def collapser(txt): |
|||
return ''.join(item for item, grp in groupby(txt)) |
|||
if __name__ == '__main__': |
|||
strings = [ |
|||
"", |
|||
'"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ', |
|||
"..1111111111111111111111111111111111111111111111111111111111111117777888", |
|||
"I never give 'em hell, I just tell the truth, and they think it's hell. ", |
|||
" --- Harry S Truman ", |
|||
"The better the 4-wheel drive, the further you'll be from help when ya get stuck!", |
|||
"headmistressship", |
|||
"aardvark", |
|||
"😍😀🙌💃😍😍😍🙌", |
|||
] |
|||
for txt in strings: |
|||
this = "Original" |
|||
print(f"\n{this:14} Size: {len(txt)} «««{txt}»»»" ) |
|||
this = "Collapsed" |
|||
sqz = collapser(txt) |
|||
print(f"{this:>14} Size: {len(sqz)} «««{sqz}»»»" )</lang> |
|||
{{out}} |
|||
<pre>Original Size: 0 «««»»» |
|||
Collapsed Size: 0 «««»»» |
|||
Original Size: 72 «««"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln »»» |
|||
Collapsed Size: 70 «««"If I were two-faced, would I be wearing this one?" - Abraham Lincoln »»» |
|||
Original Size: 72 «««..1111111111111111111111111111111111111111111111111111111111111117777888»»» |
|||
Collapsed Size: 4 «««.178»»» |
|||
Original Size: 72 «««I never give 'em hell, I just tell the truth, and they think it's hell. »»» |
|||
Collapsed Size: 69 «««I never give 'em hel, I just tel the truth, and they think it's hel. »»» |
|||
Original Size: 72 ««« --- Harry S Truman »»» |
|||
Collapsed Size: 17 ««« - Hary S Truman »»» |
|||
Original Size: 80 «««The better the 4-wheel drive, the further you'll be from help when ya get stuck!»»» |
|||
Collapsed Size: 77 «««The beter the 4-whel drive, the further you'l be from help when ya get stuck!»»» |
|||
Original Size: 16 «««headmistressship»»» |
|||
Collapsed Size: 14 «««headmistreship»»» |
|||
Original Size: 8 «««aardvark»»» |
|||
Collapsed Size: 7 «««ardvark»»» |
|||
Original Size: 8 «««😍😀🙌💃😍😍😍🙌»»» |
|||
Collapsed Size: 6 «««😍😀🙌💃😍🙌»»»</pre> |
|||
=={{header|REXX}}== |
=={{header|REXX}}== |