Solution for long repeat on checkio

I figured I’d share my solution for Long Repeat on Checkio. I got up this morning and had a few moments to solve. Did some research and found the groupby method from Itertools… there was an example online on how to use so I drew largely from that.

[pastacode lang=”python” manual=”from%20itertools%20import%20groupby%0A%0A%0Adef%20long_repeat(line)%3A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20groups%20%3D%20groupby(line)%0A%20%20%20%20%20%20%20%20result%20%3D%20%5B(k%2C%20sum(1%20for%20_%20in%20v))%20for%20k%2C%20v%20in%20groups%5D%0A%20%20%20%20%20%20%20%20occ%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20for%20_%20in%20result%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20k%2C%20v%20%3D%20_%0A%20%20%20%20%20%20%20%20%20%20%20%20occ.append(v)%0A%20%20%20%20%20%20%20%20return%20max(occ)%0A%20%20%20%20except%3A%0A%20%20%20%20%20%20%20%20return%200%0A%0A%0Aif%20__name__%20%3D%3D%20’__main__’%3A%0A%20%20%20%20%23%20These%20%22asserts%22%20using%20only%20for%20self-checking%20and%20not%20necessary%20for%20auto-testing%0A%20%20%20%20assert%20long_repeat(‘sdsffffse’)%20%3D%3D%204%2C%20%22First%22%0A%20%20%20%20assert%20long_repeat(‘ddvvrwwwrggg’)%20%3D%3D%203%2C%20%22Second%22%0A%20%20%20%20assert%20long_repeat(%22%22)%20%3D%3D%200%0A%20%20%20%20assert%20long_repeat(%22abababaab%22)%20%3D%3D%202%0A%20%20%20%20print(‘%22Run%22%20is%20good.%20How%20is%20%22Check%22%3F’)” message=”” highlight=”” provider=”manual”/]

MongoDB, standard library, considering rolling my own blog again…

As you well know, I started out rolling my own blog and couldn’t finish due to being an extreme n00b. Now that I’ve made fairly significant progress with my FlaskCasts site I am slightly considering transferring all of this over to a strictly Python blog….but….IDK. We will see.

I got hung up on a couple of things tonight trying to get my flask casts site up off of the ground. First off I really got hung up on name vs id in my form fields. Apparently Flasks Request isn’t too fond of having both a name and an ID…and playing around with Bootstrap the ID tag was automatically placed so I was stuck for several minutes…about an hour..kind of sucked. Again…SOMETHING SMALL! But…I just wrote about it…so all the while I kept telling myself IT HAS TO BE SOMETHING SMALL AND STUPID….ALWAYS IS.

[pastacode lang=”python” manual=”%20%20%20%20%40staticmethod%0A%20%20%20%20def%20update(post_id%2C%20title%2C%20content)%3A%0A%20%20%20%20%20%20%20%20mongo.db.posts.update(%7B’_id’%3A%20post_id%7D%2C%20%7B’%24set’%3A%20%7B%22title%22%3A%20title%2C%20%22content%22%3A%20content%7D%7D)” message=”” highlight=”” provider=”manual”/]

Then I ran into an issue trying to update by post…I forgot the $set (loss for a word here) and ran into some issues…luckily solved em all.

Next up…the create method. This one will be a little tricky because Ive designed the site to show posts by the slug for SEO reasons…so I won’t be able to have duplicate slugs in the database. The slugs are generated with the object/Post itself based on the title….however…I’m leaving myself the option of changing the title/content if need be. This is a simple site so…a lot of common functionality really isn’t required but its fun to think through the possibilities.


Lets do some Checkio…

30 minutes later


and it beat me…lol


working on it,…..


Preparing for the future…

Basically all I am doing is focusing on my future, by learning new skills in the present. It’s easy to get sidetracked and think of new and interesting ideas, but staying focused is the key. One of the things I have been doing is browsing Upwork projects to see what people are looking for in developers/projects. I figure if I can sift through the postings and do my best to learn as much as I can about the technologies people are paying for, my chances of being successful when I am ready to bid. When will that be? I plan on trying to roll out several of my own projects as portfolio pieces and build up a solid amount of content and once I can find a project that I am 100% confident I can fit into my schedule and accomplish I will bid. My goal is 1 year.

I’ve also had a few mobile app ideas float through my head, so learning about REST-ful API’s is on the agenda in the coming months.

As far as my FlaskCasts site…I made a few minor adjustments today. Found a couple of minor bugs I need to work out once I get a minute. Plan to work on it quite a bit tomorrow evening.

Thanks for reading!


I tinkered with the site a little here and there but nothing ground breaking today. I am just slowly piecing it together and hope to release: 9/6/17 with a couple of videos.

I love, it’s a cool  site that provides you with puzzles to solve in Python. Great learning tool. I embarked on The Angles of a Triangle today.

Never was all that great at trig but I love learning python so I tackled this one. Had help from this site:

And a library I found called Triangle Solver… 

Checkio doesn’t support external packages but I was able to dig through the code and pull out what I needed to solve this one.  Here is my solution:

[pastacode lang=”python” manual=”from%20math%20import%20pi%2C%20acos%0A%0A%0Adef%20sss(a%2Cb%2Cc)%3A%0A%20%20%20%20degree%20%3D%20pi%20%2F%20180%0A%20%20%20%20assert%20a%20%2B%20b%20%3E%20c%20and%20b%20%2B%20c%20%3E%20a%20and%20c%20%2B%20a%20%3E%20b%0A%20%20%20%20A%20%3D%20acos((b**2%20%2B%20c**2%20-%20a**2)%20%2F%20(2%20*%20b%20*%20c))%0A%20%20%20%20B%20%3D%20acos((c**2%20%2B%20a**2%20-%20b**2)%20%2F%20(2%20*%20c%20*%20a))%0A%20%20%20%20C%20%3D%20180%20-%20(A%2Fdegree)%20-%20(B%2Fdegree)%0A%20%20%20%20return%20A%2Fdegree%2C%20B%2Fdegree%2C%20C%0A%0A%0Adef%20checkio(a%2C%20b%2C%20c)%3A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20A%2C%20B%2C%20C%20%3D%20sss(a%2C%20b%2C%20c)%0A%20%20%20%20%20%20%20%20result%20%3D%20%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20round(A)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20round(B)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20round(C)%5D%0A%20%20%20%20%20%20%20%20return%20sorted(result)%0A%20%20%20%20except%3A%0A%20%20%20%20%20%20%20%20return%20%5B0%2C%200%2C%200%5D%0A%0A%0A%23These%20%22asserts%22%20using%20only%20for%20self-checking%20and%20not%20necessary%20for%20auto-testing%0Aif%20__name__%20%3D%3D%20’__main__’%3A%0A%20%20%20%20assert%20checkio(4%2C%204%2C%204)%20%3D%3D%20%5B60%2C%2060%2C%2060%5D%2C%20%22All%20sides%20are%20equal%22%0A%20%20%20%20assert%20checkio(3%2C%204%2C%205)%20%3D%3D%20%5B37%2C%2053%2C%2090%5D%2C%20%22Egyptian%20triangle%22%0A%20%20%20%20assert%20checkio(2%2C%202%2C%205)%20%3D%3D%20%5B0%2C%200%2C%200%5D%2C%20%22It’s%20can%20not%20be%20a%20triangle%22%0A%20%20%20%20assert%20checkio(5%2C%204%2C%203)%20%3D%3D%20%5B37%2C%2053%2C%2090%5D” message=”” highlight=”” provider=”manual”/]

Flask application structure…

One of the beautiful things about Flask is the freedom to do whatever the hell you want. Unfortunately, for me as a novice, this can be a huge disadvantage at the same time. Not knowing all of the best practices can cause some unnecessary headache. Lucky for me there are a lot of blog entries out there to help get this off the ground.

Blueprints is a flask feature that allows you to organize your app in a modular way. Each “section” will act almost as if it is it’s own application. I took a screenshot of my current directory structure to show you what it looks like. So the project itself would be considered a repository,

and will end up on github at some point as I make more solid plans.

Right now I just wanted to get something running even if it is technically just a simple and basic “Hello World.”

Currently the file contains:

[pastacode lang=”python” manual=”’DEBUG’%5D)%0A” message=”” highlight=”” provider=”manual”/]

When ran, it then goes to the flaskcasts directory since it is a module and runs the code in

[pastacode lang=”python” manual=”from%20flask%20import%20Flask%0A%0Aapp%20%3D%20Flask(__name__)%0A%0Aapp.config.from_object(‘config’)%0A%0Afrom%20.views.home%20import%20home%0Aapp.register_blueprint(home)” message=”” highlight=”” provider=”manual”/]

This will go to the home blueprint and execute that code:

[pastacode lang=”python” manual=”from%20flask%20import%20Blueprint%0A%0Ahome%20%3D%20Blueprint(‘home’%2C%20__name__)%0A%0A%40home.route(‘%2F’)%0Adef%20index()%3A%0A%20%20%20%20return%20%22Welcome%20to%20the%20Index%22″ message=”” highlight=”” provider=”manual”/]

The only other file is and it basically holds the DEBUG=True boolean only.


Structurally, for a very basic application that is only going to feed videos from a YouTube or similar service, this should suffice.