Links

Reformat Text Without Spaces

Tags: #text #reformat #snippet #operations #spaces
Description: This notebook reformats text by removing all spaces.

Input

Import libraries

try:
import wordninja
except:
!pip install wordninja
import wordninja

Variables

text = """WhenSatoshiNakamotofirstsettheBitcoinblockchainintomotioninJanuary2009,hewas simultaneouslyintroducingtworadicalanduntestedconcepts.Thefirstisthe"bitcoin",adecentralized peer-to-peeronlinecurrencythatmaintainsavaluewithoutanybacking,intrinsicvalueorcentralissuer.So far,the"bitcoin"asacurrencyunithastakenupthebulkofthepublicattention,bothintermsofthepolitical aspectsofacurrencywithoutacentralbankanditsextremeupwardanddownwardvolatilityinprice. However,thereisalsoanother,equallyimportant,parttoSatoshi'sgrandexperiment:theconceptofaproofof work-basedblockchaintoallowforpublicagreementontheorderoftransactions.Bitcoinasanapplicationcan bedescribedasafirst-to-filesystem:ifoneentityhas50BTC,andsimultaneouslysendsthesame50BTCto AandtoB,onlythetransactionthatgetsconfirmedfirstwillprocess.Thereisnointrinsicwayofdetermining fromtwotransactionswhichcameearlier,andfordecadesthisstymiedthedevelopmentofdecentralized digitalcurrency.Satoshi'sblockchainwasthefirstcredibledecentralizedsolution.Andnow,attentionis rapidlystartingtoshifttowardthissecondpartofBitcoin'stechnology,andhowtheblockchainconceptcanbe used for more than just money. Commonlycitedapplicationsincludeusingon-blockchaindigitalassetstorepresentcustomcurrenciesand financialinstruments("coloredcoins"),theownershipofanunderlyingphysicaldevice("smartproperty"), non-fungibleassetssuchasdomainnames("Namecoin")aswellasmoreadvancedapplicationssuchas decentralizedexchange,financialderivatives,peer-to-peergamblingandon-blockchainidentityand reputationsystems.Anotherimportantareaofinquiryis"smartcontracts"-systemswhichautomatically movedigitalassetsaccordingtoarbitrarypre-specifiedrules.Forexample,onemighthaveatreasurycontract oftheform"AcanwithdrawuptoXcurrencyunitsperday,BcanwithdrawuptoYperday,AandBtogether canwithdrawanything,andAcanshutoffB'sabilitytowithdraw".Thelogicalextensionofthisis decentralizedautonomousorganizations(DAOs)-long-termsmartcontractsthatcontaintheassetsand encodethebylawsofanentireorganization.WhatEthereumintendstoprovideisablockchainwithabuilt-in fullyfledgedTuring-completeprogramminglanguagethatcanbeusedtocreate"contracts"thatcanbeused toencodearbitrarystatetransitionfunctions,allowinguserstocreateanyofthesystemsdescribedabove,as well as many others that we have not yet imagined, simply by writing up the logic in a few lines of code."""

Model

Define function to reformat text

def reformat_text(text):
sentences = []
for sentence in text.split("."):
if len(sentence) > 0:
sentences.append(" ".join(wordninja.split(sentence)) + ".")
return " ".join(sentences)

Output

Reformat text

print(reformat_text(text))
Last modified 1mo ago