May 2, 2008

 

My First Blog Post Is Lame

 

Instead of a proper first entry, the kick-off to my blog is a description of a Python program that scrambles the text of an ill-fated first blog post, along with the scrambled text.

 

Let's Get This Blog Started

 

What do you do when you are stuck on high-center, with wheels spinning and mud flying, but with no forward progress? You punt, or you re-start, or you modify -- or you do something odd and useless, just to get moving.

 

I've been trying to make my first blog post all week. I made the decision to write it as a biographical sketch, with an aim at explaining my world view, in the spirit of Earth Day . But, no, that was a dumb idea. There is too much history to summarize easily. I went off on fun tangents, recalling this and that from my childhood, writing with a chain-of-consciousness style, which might work in snippets, but maybe not in a big post, especially the first one. People probably get stuck on how to do their first blog post, and hem and haw, and may never get past it, never to even start a blog. So, I guess you just need to dive in, with something small. A blog is a good place to share blurbs on this or that, remembrances of something specific, recipes for doing tasks, or whatever items are appropriate for a blog style. A story emerges as blog posts accumulate.

 

A Python Program To Scramble Words

 

I wrote a little Python program to scramble the text of the ill-fated and unfinished first blog post. I'll be posting on Python programming, so, if anything, this is an appropriate start. Explanatory comments are sprinkled into the code (comments in Python start with a # sign). Here is the program, as raw text:

 

# This program reads a blog post and breaks it into words.

# It is a special case program, not robust for general

# application to text. It is a one-off program to get the

# job done, combining normal programming with special case

# handling. It breaks phrases apart, such that the name of

# my hometown, Plain Dealing, will appear as separate

# words, Plain and Dealing, somewhere in the list.

 

# Import Python's random module, which we will use below:

import random

 

# Make a list for holding the words.

words = []

 

# Go through the lines in the text, which is read from

# a text file. There are two steps in one in the for

# line, with open('blog_post.txt') opening the file for

# reading, and .readlines() for reading the lines:

for line in open('blog_post.txt').readlines():

  # Go through the words on each line:

  for word in line.split():

    # If the word isn't 'em or doggin' (special cases,

    # for words found in the text by inspection):

    if word not in ['\'em', 'doggin\'']:

      # Get rid of starting and ending punctuation. This

      # isn't an exhaustive treatment, but it works for

      # this task. Note that periods, and quotes must

      # be escaped, with slashes, in text strings. The

      # while is used so that in the case of a word that

      # is in quotes, against a comma, as in 'word,', the

      # punctuation will be stripped until either the

      # word is empty, as with '--', or a non-punctuation

      # character is reached.

      while len(word) > 0 and word[-1] in '\.\'\",?!);:-':

        word = word[:-1]

      while len(word) > 0 and word[0] in '\'\"(-':

        word = word[1:]

    # If the word wasn't all punctuation (would be

    # zero-length), add word to the list, if it isn't

    # already in there:

    if len(word) > 0 and word not in words:

      words.append(word)

 

# Among its shortcomings, this program doesn't try to

# distinguish words by case, so that the word list will

# include both the word and, with lowercase 'a', and the

# word And, with uppercase 'A'.

 

# Use the random module to shuffle the word list.

random.shuffle(words)

 

# Use the join method to make a big paragraph with

# all the words separated by blanks:

big_paragraph = ' '.join(words)

 

# Print the big paragraph, along with a word count:

print

print 'The big paragraph has', len(words), 'words.'

print

print 'Here is the big paragraph:'

print

print big_paragraph

 

And here it is without the comments:

 

import random

 

words = []

 

for line in open('blog_post.txt').readlines():

  # Go through the words on each line:

  for word in line.split():

    if word not in ['\'em', 'doggin\'']:

      while len(word) > 0 and word[-1] in '\.\'\",?!);:-':

        word = word[:-1]

      while len(word) > 0 and word[0] in '\'\"(-':

        word = word[1:]

    if len(word) > 0 and word not in words:

      words.append(word)

 

random.shuffle(words)

 

big_paragraph = ' '.join(words)

 

print

print 'The big paragraph has', len(words), 'words.'

print

print 'Here is the big paragraph:'

print

print big_paragraph

 

Results

 

Here is what the program prints -- the contents of the first blog post, totally scrambled (You might find an interesting or intriguing word or two):

 

The big paragraph has 945 words.

 

Here is the big paragraph:

 

Canyon haunt did sits Vietnam were stained patchwork Mr sometimes stumps pottery 30-30 real straw Rosston It saws prize traumatized sardines moving this self-awareness defoliant to Mike's we wormed A among Love took row neighborhood different chasing forms speed shipping mice BB That's mow sloughs My Highway seat flourishing panhandle areas disgust boy Kitty air starts self broad night Why Ray milieu pumped church door everyone spear yellow woods hard do even playing war dying crop bench Thing like platform play melted pond angry intense horses Milton's gin hear gate along Hendrix pens trails Big profound Start wanting pickers make Mama 30 Bob seeing soul mystic strip chain-of-consciousness excitement tiny Lu also Ditch baby Chevy set pretty dogs that deacon Line pine behind of decades Jennings way sculling 527 fields hackberry name D fixing Purple us seen And deaths racial viewing grass pinoak Mighty back-flips a thousands blackbirds barren man pecans Lee 6 mixing saw orchard now crossing Milton pellet by slap rained tapes screaming ski clamped poker Charlie pranced islands spurred Gill others Austin red riverside House thick bob-tail Baptist bug Robert trees borrow fuzzies intellectual doctored wooden meant ghosts exposing Rachel age Dogwood dams Ba'coon boats there types oaks all Its developed Rain dam jokester hunt involved word is Philip smell line more happened Half Pittman ride from Arnold hikes Canada Some doggin' Bayou antlions level true conservation mama flats be castrated Dixie gun piles tobacco don't Life both Road stripes how reunions as almost paper Wilson bouncing craps hay liberating orchestrating Happy house seven coconut lore prayed noticed Mike should shooting 200 palate Home least trapped every flood still Wieners teal was power floodplain planter on Mother Oklahoma basketball top couldn't dehorned beauty 14 mule football stood cypresses whip killing mistake under time snipe pines winds ash Nature What bank sand bass brother's Uncle graduate killed With Unit act near ice whom fly than discussions middle-busters rocking hiking those benches place north Duro Dynap army boat hundreds chewing years secret realization bin yellow-handed soon millions favorite when Ridge Louisiana Not into nutria piney middle habitats loam hole huge scream anhingas mowing few goal Shreveport wells shame awareness miles coves rabbits around Yazoo ducks interim school cottonwood deep ire see So blinds blackberries confusing Indian his Bodcau goners River farm earliest Who's Crawford Sam friends brim Barnett awesome shallows hub Overcup northwestern train love duck relaxing referees they eyes pecan Volkswagon bobbing myself Hal pumphouse mixture manure clear-running guts Ah formerly Rabbit Gladys tractors Horneman validity where turning moccasins got forest creeks except requirement campouts cookies say chickens at are Jake Bermuda self-honesty later churned me spread lake milling leased Cloudy great corner owned boundary Surprise buzzed open road owning mud check attack fling inside Stillhouse flooded Thunder International beaver land cuts block spawning about cutoff asking memories bill black people ranging faith flowing lots The store creek minks tire south II wood stage Co-op purpose Joe treehouses combines soil next gates bust beautiful little view brief who older parents shallow appreciation long cursing Pearl boasting Giant much hogs babies Bottoms Something closing taken flat-bed over School bridge cold campfires momentarily daughters religion up been with Geri lure but bluejay Real full-speed fishing dirt looked gas walls beavers Mother's corks could Island Completely circus good thought via fast high smiling forever torpedo morning Montana parcels rats frogs teary pipes hills waters multiple points proud Tat trucks clear preacher charcoal stream across grew kind High our engine brought Woody always Daddy boyhood Jimi things Miller's dusk climbed honesty Aunt wild disks look acknowledgment maybe visions holes Texas Arkansas became environmental finally tales foot daughter hissing without band which Haze ten heroes many Eagle Harvester down Cutoff Dick's treetop funerals light Dealing garden usual lie accepting wurdy-gurdy swimming bowing grease kids activity noise horse brothers tires Second one rushes ticks head-chute reconnected morphed intertwining building only something J gone flow free tree brother track Smokey walnut old Luke Jeff dove Faith surfing Lake mountains spinning waited their Snowy Red romped area laughter combined meaning hardwoods between didn't stop fever saving before spring-fed rhythm connection water arrowheads sudden beanee-weenees cleft worked its here understand deserts radios Oak personal Palo not quarterhorse Stinson large came bite cables hat enough fish Hank know allow fear Dallas stark out so Evans oil let or guns yard Bill sauce made Bluff side cattle cistern Master brigades Roger's forts flat doesn't head Different having would continued ready dog In camp Aiken Across praying Place VW then lining why college world galore birds patio rolling rusted worms Old trailers willows Around scout clearing swing river story mysterious driving cutting weddings These year roosting snakes treks lost shoot rod scattered bit you must cast acres for running and visited blood chairs marvelous cotton each farmed steps timber pit dusters flailing swinging sick while corral For arm through logs stress steep it slab sandbars surprise lands announced an full talk Tank cypress home trip Doing regrowing R anger Lightning really geese marshlands drinking chain pastures heart-pounding first onions such big fancy Plain White yo-yoing I concrete lined Cox hammers hometown standing mulberry C upbringing lonely absurdity eight wheels my during leaving rope sure in jonboat prairies possum no emboldened crazy feet heater leap 'em Hail family has Thelma plodded afternoon Denny take metal Sonny's egrets dust lures Drive bottom cutbank master yourself off coyotes knew go beyond felt warm after her hot winter matter some central cows forces casting floorboard Here lived burning tracks whooshing several Alice Levee surged there's pasture other giving chestnut had That the Moon precious tall boys Sandy giant barn related psyches men back tighter end account that's 20 Jumping

 

Someday maybe I'll take the original text and post it as a proper entry.