better living through python

An adventure in programming and recovery.

Python Lesson

August 16, 2011
Problem Set 3, problem 3; I’m learning more and more that I didn’t follow exactly what they wanted when creating these functions.  Thus my current frustration with my lack in organization in regards to my code.  Several of my functions should have been more separated, but ended up intertwined making it difficult for them to operate without each other.
For this function I need three different variables (starts1,starts2,length).  Starts1 and starts2 are the list of locations the prefix and suffix were respectively found.  Length is the total length of the prefix of, example, “atg” which could be “at”.  The function I need to create must create a list of combinations with a space between the two different substrings, or prefixes and suffixes.  This represents the possible misspelling.
I begin in my function by identifying my list as ‘finalmatches’, and m as equal to length.  Then I proceed to process the starts1 and starts2 lists through two “for” loops.  These two loop sets will compare all the different possible combinations of substrings with the addition of one space.  It will then add all of these combinations to the list “finalmatches” and return that last back into the code for use after that function is called.             

 

Python Lesson

August 15, 2011

 

Now it’s time for Problem 2.  Continuing on from where we left off yesterday, problem two adds to this problem.  
At this point you’re asked to create a function with two inputs.  We’ll, after reviewing my work I realized that I reworked the answer to this function into another function that worked more appropriately to solve steps 3 and 4.  Here I was supposed to create a function that would, based on two inputs, create a list of all the starting points where a key would show up in the string.  I remembering creating that output, but then moving on in the problem anyways.  So, instead, I’ll show you the next function in my Problem Set.  

This next function I created was to solve one problem, it was to create a list of the prefixes and suffixes for whichever key is indicated.  
Here I start with two variables, “x” and “z”.  “Z” represents the position in the key where we are currently starting our slice from.  “X” is the countdown, where the total amount to count up to is dependent upon the length of the key.  For key “atgca”, its total length it 5.  Then I create the list of prefixes and suffixes and call it “finallist”.  
Next step is a while loop, where I indicate as long as the total value of x is less than the total length of the key provided, you continue to do the following actions.  Those actions are first: using slices to create all the different prefixes and suffixes that occur for that particular key; then: for each pair of prefix and suffixes, you append them to your “finallist”.  For each run through the while loop, there is a z+1 in the suffix creation.  That means, that the suffix starts one after the prefix ended, so that we can create a function that allows for misspellings.  It also allows for the function to continuously go through the list until there are no longer any letter to slice.   

Creating this function took much longer, and was one of the longer hangups during this Problem Set, because I had never interacted with slices before.  A slice, is a python term for taking/using only a part of a string.  To indicate where you wish your starting point to be, you must simply say what position to start at (position number being 0 through however long your string is).  I’ve a better understanding of slices now, and that help a bundle during the next couple of functions.  

 

Cheers to a successful Kickstarter project!

August 12, 2011
This entry is dedicated to all of our fantastic supporters out there!  Whether you pledged to our Kickstarter project, helped out by tweeting or sharing about it, or both, we want to make sure you all know how very much we appreciate your support.

Thanks to your support we’ll be able to devote the necessary time and resources to creating this software.  We’ll also be able to continue development of our other projects in the time remaining.  Here is a picture of us celebrating!

Here is a picture of our cats celebrating!

Suffice it to say they were not excited, they really couldn’t have cared less.  We did attempt to ‘get’ them excited, but they weren’t to happy about that either.  If you haven’t been to the site recently, here are the final results.  

<iframe frameborder="0" height="380px" src="http://www.kickstarter.com/projects/1241383920/open-source-programmers-text-editor-using-canvas-a/widget/card.html" width="220px"></iframe>  

Thanks again everyone!  

 

Using Kickstarter to fund an Open Source project

August 11, 2011

Today we met our Kickstarter goal!!  Jointly we wrote a reflection on our current experience thus far, and it is posted to the FlamingLunchbox blog.  Therefore, for today, I am linking to that blog post as my blog post.  I hope you enjoy it!

 

Python Lesson

August 10, 2011

Finally a review of the most recent programming problem I was working on.  In this problem you interact with DNA strings and pre-identified keys.  These strands can be of varying sizes, and are given to you in the beginning.  Here is the description of the first problem set.


Here I’m asked to create two separate functions that will iteratively and recursively solve the problem.  Just a quick refresher for those not familiar with programming, a function is a definition created within programming code to do a certain thing.  It will be unique to your file.  It’s like creating a new word for one document so you can make sure the same thing happens every time you type that word again.
 
An iterative function, is a function that will use a loop to process information.  Such as a ‘for’ or ‘while’ loop.  Both of these can create loops within code to process information.  A recursive function is a function that refers to itself in order to process the information.  A recursive function can be more helpful in certain situations, because it can make the amount of code you need to write much smaller.  It can also, sometimes, make it more easily understood.  

First I created an iterative function that would solve the problem.  It is shown below.

Here I’m using the find keyword in python.  What this keyword does, is it searches through the first item listed (target), and searches for instances of the second (key).  This basically solves almost the entire problem.  Next I just need to make sure my function spits out a list once complete.  To do that I simply identify a variable (“t” in this case), and make it equal to the symbol for a list.  To make a list you say t = [ ].  The brackets signify the list, versus parenthesis which indicate a tuple.  

The next step in this function is the while loop.  This loop states that while x is less than -1, you will continue to do the following steps.  Those steps include adding each item string location found to be added to the list “t”.  It also states that once a location is found, you start one after that location during your next time through the loop.  Once completed this function will return a list of all the times the key will show up in the target DNA string.  

Next, onto the recursive version of this function.  First off it’s important to note that for some recursive functions to repeat only a certain number of times, it must recognize where to stop.  For this I added an additional variable.  That is why instead of just the “key” and “target” you saw above, you see an additional “x” here.  That “x” represents the current position in the string.

I’ve found that recursive functions, while shorter and more concise in coding, can be more complex to understand.  It compacts logic into a smaller space, at least it does in my own brain.  As you can see I’m still using the find keyword as I did above, however this time I have the additional variable at the end “x”.  This “x” represents the starting position where the find keyword is to begin in the list.  Thus if the “x” were noted as “0” when the function is originally called, then it would be starting at the first position.  

Next you see that if “x” were to equal -1 (or the end of a list), then it would return an empty list in response.  Now here is the tricky part of recursion.  The “else” aspect of this function is where the function calls itself to solve the problem.  Here the function will add 1 to “x” and then append (add) the current value of x to the list.  Thus the final list is created.

More canning and programming

August 09, 2011

As I said in my previous post, it’s canning season.  I picked up 22 lbs of cucumbers and 9 lbs of blueberries this past weekend.  The cucumbers are now salting, the first step towards bucket pickles.  The blueberries will be canned here in the near future.

On the bad side I’ve been sorely neglecting my blog.  Even though it’s not like I wasn’t busy, most of it wasn’t work busy.  I was up til midnight last night working on cucumbers and doing dishes, getting things ready for canning today.  You see, we don’t own a dishwasher, so washing dishes takes a ton more time than normal.  We enjoy it more this way but it sure does slow some processes down a fair bit.

We’ve only 3 days left until our Kickstarter project is finished.  That means I’ll be focusing a bit on getting the word out there.  Luckily, however, I have time to start work on my next programming problem; Simulating a retirement fund.  I’m sure I’ll be tweeting about my conundrums later today.  Woo debugging! :)      

 

A little blackberries, a little coding and PIE

August 04, 2011

Good Morning world.  I’ve been rather absent of late, but in order to prove my usefulness I am going to post pictures of the berries I picked this morning.
 It is the growing season and as a lover of canning and gardening I’ve found myself caught between the want to focus more heavily on programming, or canning the entire valley’s produce.  I’ve settled for a little bit of both.  This morning I spent the better part of 3 hours picking berries with my mother and niece Kate.  It was grand weather and the air was drenched with the scent of sun-baked blackberries.  I’ve got a bit of a sunburn but the trade-off was definitely worth it.  

Now that I’ve finished discussing my little bits of canning and berries, I’ll get back to the more important stuff.  My current programming problem.  I’ll be going over the whole thing in detail over the next couple of entries, but for now I’ll give you a quick run down of what the problem is.

It starts off with a DNA sequence.  You’re given two different DNA sequences and a set of identified strands and sub-strands of DNA.  You’re then asked to write some code that will be able to go through the list and find where the DNA strand starts in the sequence.  Then you you know how many times that identified DNA strand shows up in the sequence.  You’re also writing two different functions to solve step one.  One function is iterative, and the other must be recursive (when a function will call itself in order get the needed results).  That’s step one.  

In step two you create a list of all the points where the strand shows up in the sequence.  In step three it becomes a little more complicated.  Step three involves the mutated DNA strand.  At this point you have to divide up the strands so that you can provide a list of the different alterations that could occur.  For example, a DNA strand that was “ATG” has mutated.  It could be “ACG” or “AAG” or “AGG”.  To allow for the mutation, you must allow for that middle spot to be blank.   The limit to this problem is that there is only one mutated piece allowed per identified DNA strand.  

I am to finish part four of this problem today.  I’m still wrapping my head around what it’s asking for.  I’ll let you know what I find out later.           

 

The "featured" section phenomena for tech companies

August 02, 2011

 

What does being part of a “featured” section mean?  By a “featured” section I’m talking about those sections that are supported by most big markets.  Amazon, Chrome Marketplace, Android Market, and so on.  Even Kickstarter is a culprit.  It’s quite sad that so many of these websites provide a “featured” section, and thereby tend to be known for supporting startups or independent application developers.  It’s sad because the overwhelming evidence shows it’s simply not true.  

If you look at so many of these sites you’ll see that a majority of their “feature” applications are actually from big-name companies.  So if you’re a big-name company it works out, you’ve got the in.  Another aspect is that they simply won’t feature you unless you having something that has lots of bling and flashy lights.  To understand more why I say this, simply view the Kickstarter page describing a “featured” project.  They indicate you need not only a good following but also an intriguing video and creative idea for your project.  All these caveats, in fact, still simply indicate that to be featured, means to be hand chosen.   

Alright, I know I’m complaining here, but this is honestly frustrating.  We aren’t unwilling to put the effort in but half of this featured action is all about who you know.  We’re in small town Corvallis, we don’t know many people.  With over 6,000 facebook likes, I feel like our products aren’t something to shirk at.  Then more of the frustration is simply because it doesn’t feel like these big-name companies want to help the startup.  They need to keep their money floating and producing, so they don’t bother truly supporting those who can come up some of the startling  innovations out there.  Now dies my admiration of big tech companies, and in its place is, “Oh yeah, they’re just another big company...they act like all the others do.”

Therefore when you have other underhanded things, like the app-of-the-day Amazon treatment, you’re not as surprised.  In case you’re unaware, it seems that most people who become app-of-the-day for Amazon are asked to sign a last minute agreement that states they actually won’t get any money for their app, and they must actually give it away for free if they want to be app-of-the-day at all.  So, unless you’re already popular enough that you can “negotiate”, you actually don’t get anything from app-of-the-day except one large free give-away.  You get promotion, but no actual money.  Since you’re giving away you’re paid version, how much does this really help you?  So wait, how does that help the fledgling developers?  How do these supposed “Tech Giants” actually support startup gaming companies again?  I understand these “featured” sections are actually to support the their own market.  I guess I wouldn’t be so upset if these big companies were just honest and stopped claiming to be support the small developer.   

 

How grammar can change your perceptions of a great idea

July 29, 2011
As someone who speaks another language, and has studied several others I always find it humorous when people become super sticklers about grammar.  Don’t get me wrong, grammar is necessary, but I’ve lived in situations where grammar wasn’t as necessary as understanding.  To be picky about grammar sometimes kept some exchange students from speaking up at all for fear of saying something silly.  How are you supposed to learn the correct way to do things unless you go forth without fear of doing something wrong?  
 
Unfortunately I had the gumption to learn German as my main secondary language.  Germans are very proud of their language (as they should be) and thus are very particular about grammar.  Many of their grammar rules make logical sense and German spelling is fairly phonetic, yet despite it’s logic there are plenty of German grammar rules.  So I choose to study a language spoken by a group of people very particular about grammar, with precise logical grammar rules and lots of them.  Suffice it to say, I was corrected a lot.  
 
Now, without those corrections I would never have become a bietter German speaker.  So with this logic, it brings me to this question.  Why do I criticize others for poor grammar online, especially when I don’t know what their native language is?  For many people online it’s not apparent.  In the US especially, where many people come from various different historical backgrounds, you can never know what their native language is.  There are many Americans whose parents speak their home countries native language, but they themselves do not.  Yet, I believe, they are still affected by the exposure to their parents quasi English skills.  Should we judge or criticize their grammar more because of a circumstance they had no power over?  Especially when we really have no way to tell one way or the other?  Not to mention, when they’ve already worked harder to get there than many of us have.

To assume that the person is a native English speaker when they post in English online seems unfair.  If they are not, we are taking in a certain set of criteria when determining their “abilities” and we are judging them on it.  Many will argue, what other option do we have?  Which, when it comes down to that, you’ve found yourself in an argument for or against stereotyping.  Many of the great artists and creators out there had a rule that encouraged idea growth; don’t knock it till you’ve tried it.  Look at many of the great hackers out there, they try not to judge because who knows where the good ideas will come from?  

With this thought in mind I will continue to plow ahead.  I will also try to take my own common sense to heart and do my best not to allow judgment to occur when I see grammar errors.  Just because someone cannot communicate with you on your level in your native language, doesn’t mean they don’t know what they're talking about.                 

 

Should basic programming be required in public education?

July 28, 2011

 

Every day I am more and more convinced of the different social class that exists when it comes to programmers.  Anyone who has the time and inclination to become a programmer (most of the time), has been presented with a life situation that allows them the time and concentration necessary to learn programming.  

One of the side aspects that comes along with being a programmer seems to include the ability to divide processes into more easily completed chunks.  This ability is extremely valuable in almost all professions.  This leads me to believe, especially with the growth and dependency on technology, that basic programming should be a minimal requirement in highschool.

What would teaching basic programming and computer education bring to public high school education?  Increased problem solving ability.  I believe it would significantly increase the ability for many students, to interpret and solve a variety of problems from mathematics to social ones.  Increased computer education would increase the base knowledge of our population and lessen the amount of stress on IT departments.  I also think it’s necessary that the next generations are taught the basics of online safety.  Not simply viruses, but also on the effects from online social interactions.  In turn this could help to further protect our populations from scams of a variety of natures, and simply provide some basic understanding of what to watch out for.  I think that if this could be done effectively it would highly benefit our society as it grows.    

 

Links