A Code Scribbling Session
My mad plan here is to play a little Katamari Damacy with the Fizz Buzz problem. I want to start simple and just add thing after thing until it turns into a big ball of chaos. We'll start with a basic loop and modulus operators. Here is that.
Let's shorten this up with some ternary operators.
Okay, that was concise. Time to make it more interesting. What if the two ternary operators were concatenated together and thrown into a list comprehension? The fizz and buzz ternary expressions have to be wrapped in their own sets of respective parenthesis. This ensures that it evaluates correctly. The "==" aspect of the modulus expression can be reduced to something more "truthy" so that it fits nicer in a blog post. Here's what that looks like.
Interesting if a bit of a space eater. A generator expression would make it lazier. At the very least, it won't make the code look any worse than before. Here's that code.
What else could be done with this? Here's an idea. Those ternary expressions could be wrapped into a lambda function. Here's the result of that.
What else? We could take the string formatting out of the print statement and put that in the expression. Then, the for loop just has to loop through the resulting list of strings.
Hmm. Come to think, why have the for loop at all? The string join method could just join them all together with newline characters to ensure it prints like before. Then, the print statement just has to print one big string all at once.
Hooray, no more normal for loop! But this is interesting. That entire expression we have could be made into it's own lambda expression in and of itself. You could even pass an argument and print the result of that. Here's what that looks like.
Okay, what's next? There's no reason why we can't just move the entire expression and evaluation into the print statement itself.
It's all one big blob now. The print statement uses the expression here. But wait! There's no reason the print couldn't be a PART of the expression.
Where do we take it from here? Let's see. Meta-programming perhaps? There's nothing saying we can't create a nameless class with a __call__ method. Then it's just a matter of making an instance. From there, it's just a matter of taking advantage of __call__ and invoking the instance as if it was just another function.
This cake is baked. Let's decorate! I'll just wrap the __call__ function in a staticmethod decorator and make that troublesome self argument go away.
Awesome! All wrapped and decorated. And we're done with this scribbling session.
What a Mess!
This is obviously not meant for production code. This is essentially unfettered silliness enjoying some time in the sun. Such is what creativity is. It might accidentally lead to actual innovation but that's besides the point. This is about taking some time to set your brain free.
So make it a priority this year to relax. Have fun. Scribble.
So make it a priority this year to relax. Have fun. Scribble.
Mic Drop: https://gist.github.com/ryanseddon/2631637
ReplyDeleteawesome Python!
ReplyDeleteHow about this? https://github.com/tacticiankerala/elixir-haskell-ruby/blob/master/fizz-buzz/fizz_buzz.rb
ReplyDeletePS: This is written in ruby but, hardly takes any time to convert to python
The output is not as per the requirements; it is supposed to be "FIZZ" or "BUZZ" or "FIZZBUZZ" or the number itself
ReplyDeletePower BI Course Online
ReplyDeleteEnrolling in a Power BI course online can really boost your career prospects. This course is worth exploring: power bi certification training. It covers dashboards, reports, and data modeling. The hands-on approach makes learning effective. Great for beginners and professionals alike.
Salesforce Admin Course
ReplyDeleteSalesforce admin course is a good career option. I found this salesforce admin course useful. It explains concepts clearly. Easy to understand. Helpful for beginners.
Great overview! devops and aws training
ReplyDeletehelps in understanding deployment pipelines and automation strategies. It enhances productivity and speeds up delivery cycles.
I found this servicenow online training content very useful and easy to understand.servicenow training
ReplyDeleteMuleSoft developer training focuses on building APIs and integrating systems. It is ideal for developers looking to expand their skill set.mulesoft developer training
ReplyDeleteMuleSoft developer training is essential for API integration roles. Nice content!mulesoft developer training
ReplyDeleteInsightful article! Our devops with aws training
ReplyDeletefocuses on real-world skills like CI/CD, monitoring, and infrastructure as code, helping learners streamline software delivery efficiently.
The ServiceNow administrator course covers everything from basics to advanced configurations. Definitely a good starting point for IT professionals.servicenow administrator course
ReplyDeleteGreat read! Learn dell boomi training
ReplyDeletewith practical experience in real-world integrations, helping you build strong iPaaS skills for career growth.
Salesforce CPQ training helps you learn pricing, quoting, and sales automation to improve business efficiency.servicenow course
ReplyDeleteThe ServiceNow training classes offer practical knowledge with expert guidance.service now training classes
ReplyDeleteServiceNow training classes offer hands-on experience with real-world scenarios.servicenow training classes
ReplyDeleteservicenow training classes – ServiceNow training classes are well-organized and help in understanding core ITSM concepts step by step.servicenow training classes
ReplyDeleteThese MuleSoft classes seem helpful for understanding integration concepts clearly.mulesoft classes
ReplyDeleteTableau Developer Training
ReplyDeleteThis is a great post for understanding Tableau basics. I also found this tableau developer training. Sharing it here in case it helps others.
Power BI classes online help learners understand dashboards and business insights easily.power bi classes online
ReplyDeleteNice write-up. Sales force developer training is really helpful for understanding real-time Salesforce projects.salesforce development training
ReplyDeleteSalesforce admin course online allows flexible learning of CRM administration skills including dashboards, reports, and user management.salesforce admin course online
ReplyDeleteA salesforce developer course covers Salesforce coding, automation, and integration skills required for high-demand IT jobs.salesforce developer course
ReplyDeletePower BI live training sessions are very useful because learners can interact directly with trainers and clarify doubts instantly.power bi training online classes
ReplyDeleteA well-structured Salesforce development training program with practical exercises and live projects. The course helps learners understand coding, automation, and application development in Salesforce effectively.salesforce development training
ReplyDeletePower BI classes online provide flexible learning opportunities for mastering data visualization and reporting tools. Students can work on live projects and gain practical experience.power bi classes online
ReplyDeleteThis Salesforce developer training article provides great insights into CRM development and certification preparation. The real-time project exposure looks highly beneficial.sfdc developer course
ReplyDeleteExcellent Salesforce dev training with real-time coding examples and project-based learning. The course is suitable for aspiring Salesforce developers looking for career growth.salesforce dev training
ReplyDeleteA Salesforce admin course teaches user management, reports, dashboards, and workflow automation, preparing learners for CRM administration roles.salesforce admin course
ReplyDeleteA sales force admin course is ideal for beginners who want to start a career in CRM systems and cloud-based business solutions.sales force admin course
ReplyDeletePower BI online training is the perfect way to learn data visualization, dashboard creation, and business intelligence skills from anywhere. It helps learners gain practical experience with real-time analytics tools used by top organizations worldwide.power bi online training
ReplyDeleteEnroll in the Tableau Course Online to learn data visualization and analytics from industry experts. Understand dashboard creation, data connections, reporting techniques, and visualization best practices through live online sessions.tableau course online
ReplyDeleteVery detailed article. Finding the best PowerBI training online is important for anyone planning to start a career in business intelligence and analytics.best power bi training online
ReplyDeleteSalesforce developer training is designed to teach real-world development concepts, including automation, APIs, and cloud solutions.salesforce developer course
ReplyDeleteGreat post about the best online Power BI training. Online courses provide flexibility and practical learning opportunities for students and working professionals alike.”best online power bi training
ReplyDeleteThanks for sharing this informative post. The Sales Force Admin Course provides essential skills needed to manage Salesforce environments and support business operations effectively.sales force admin course
ReplyDeleteOnline Salesforce Developer training programs are perfect for individuals looking to gain development expertise through flexible learning. The hands-on projects and industry-focused curriculum help prepare learners for real-world Salesforce development roles.online salesforce developer
ReplyDeleteSFDC Admin Course provides foundational knowledge of Salesforce CRM administration. It helps learners understand how to manage users, objects, and business processes within the Salesforce platform.sfdc admin course
ReplyDeleteTableau Developer Training helps you master dashboard development, data visualization, and business intelligence reporting. Gain hands-on experience with real-world projects and industry best practices.tableau developer training
ReplyDeleteExcellent article! Tableau Developer Training is a great way to build advanced data visualization and dashboard development skills. Thanks for sharing such valuable insights.tableau developer training
ReplyDeleteExcellent article! Tableau Developer Training is an excellent way to gain expertise in data visualization, dashboard development, and business intelligence reporting. Learning Tableau can significantly enhance career opportunities in analytics and data-driven decision-making.tableau developer training
ReplyDeleteGreat article! Power BI Online Training is an excellent way to learn data visualization, reporting, and business intelligence skills that are highly valued in today's data-driven organizations.power bi online training
ReplyDeleteExcellent post! A well-structured Tableau course online can help learners master data visualization, analytics, and reporting techniques. Thanks for providing such valuable insights.tableau course online
ReplyDeleteA Salesforce Developer Course covers essential development concepts such as Apex programming, triggers, Lightning components, and API integrations. It prepares learners for successful careers in Salesforce development.sfdc developer course
ReplyDeleteA Tableau Online Course covers essential topics such as data connections, dashboard creation, data blending, calculations, and visual analytics, helping learners build job-ready skills.tableau online training
ReplyDeleteQuality Tableau online training helps professionals learn how to create impactful dashboards and reports. A strong training program combines theoretical concepts with hands-on practice to build confidence and expertise.tableau online training
ReplyDeleteI found this article while searching for salesforce developer training, and it answered many of my questions. Practical assignments and real-time development projects are essential for anyone planning to become a Salesforce developer. Thanks for the useful content!salesforce developer classes
ReplyDeleteA professional Salesforce Developer Training program should combine theory with practical implementation. OnlineITGuru focuses on hands-on learning, coding practice, and real-world scenarios to help students gain confidence.
ReplyDeletesalesforce developer classes
Very useful article. A Salesforce developer course offers a structured learning path covering coding, application development, APIs, and platform customization with practical examples and live projects.Very useful article. A Salesforce developer course offers a structured learning path covering coding, application development, APIs, and platform customization with practical examples and live projects.
ReplyDeleteReally enjoyed reading this blog. Online Training Tableau programs are a great option for anyone looking to strengthen their business intelligence and reporting capabilities.online tableau course
ReplyDelete