<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>programming Archives - Tech Chronicles</title>
	<atom:link href="http://kostacipo.stream/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://kostacipo.stream/tag/programming/</link>
	<description>Ramblings of a Tech Dude</description>
	<lastBuildDate>Wed, 22 Jul 2020 21:59:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://kostacipo.stream/wp-content/uploads/2019/12/cropped-profile-32x32.jpg</url>
	<title>programming Archives - Tech Chronicles</title>
	<link>http://kostacipo.stream/tag/programming/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>7 Skills of Highly “Effective” Programmers</title>
		<link>http://kostacipo.stream/7-skills-of-highly-effective-programmers/</link>
					<comments>http://kostacipo.stream/7-skills-of-highly-effective-programmers/#respond</comments>
		
		<dc:creator><![CDATA[Majordomo]]></dc:creator>
		<pubDate>Wed, 22 Jul 2020 21:59:56 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[programming]]></category>
		<guid isPermaLink="false">http://www.kostacipo.stream/?p=1801</guid>

					<description><![CDATA[<p>&#160; Software engineers spend a lot of time gaining skills for interviews by practicing leet code problems and perfecting resumes. Once they finally get that job at a startup, Google, Amazon, or another corporation, they might find the skills they used to get the job don’t match the ones they need in their everyday work. [&#8230;]</p>
<p>The post <a href="http://kostacipo.stream/7-skills-of-highly-effective-programmers/">7 Skills of Highly “Effective” Programmers</a> appeared first on <a href="http://kostacipo.stream">Tech Chronicles</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<section class="di dj dk dl dm">
<div class="n p">
<div class="z ab ac ae af dn ah ai">
<p id="b1d8" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Software engineers spend a lot of time gaining skills for interviews by practicing leet code problems and perfecting resumes.</p>
<p id="ccb1" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Once they finally get that job at a startup, Google, Amazon, or another corporation, they might find the skills they used to get the job don’t match the ones they need in their everyday work.</p>
<p id="b839" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Here are our seven skills of effective programmers.</p>
</div>
</div>
</section>
<hr class="iv ck iw ix iy iz ia ja jb jc jd je">
<section class="di dj dk dl dm">
<div class="n p">
<div class="z ab ac ae af dn ah ai">
<h1 id="96f2" class="jf jg as ar jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw jx eh" data-selectable-paragraph="">1. Learn How to Read Other People’s Code</h1>
<p id="f1f6" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph=""><mark class="uq ur lw"><img fetchpriority="high" decoding="async" class="pg uk s t u ho ai hy" src="https://miro.medium.com/max/744/1*aF4L0WQV77WPd1MW3r530Q.png" sizes="700px" srcset="https://miro.medium.com/max/276/1*aF4L0WQV77WPd1MW3r530Q.png 276w, https://miro.medium.com/max/552/1*aF4L0WQV77WPd1MW3r530Q.png 552w, https://miro.medium.com/max/640/1*aF4L0WQV77WPd1MW3r530Q.png 640w, https://miro.medium.com/max/700/1*aF4L0WQV77WPd1MW3r530Q.png 700w" alt="Image for post" width="744" height="612"></mark></p>
<p class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph=""><mark class="uq ur lw">Everyone but you writes terrible code.</mark></p>
<p id="039e" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">That is why a great skill that has multiple benefits is being able to follow other people’s code.</p>
<p id="965d" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">No matter how messy or poorly thought out a previous engineer’s code is, you still need to be able to wade through it. After all, it’s your job. Even when that engineer was you one year prior.</p>
<p id="a754" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">This skill benefits you in two ways. One, being able to read other people’s code is a great chance to learn what bad design is. While you are looking through other people’s code you learn what works and what doesn’t. More importantly, you learn what type of code is easy for another engineer to follow and what code is hard to follow.</p>
<p id="b330" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">You need to make sure you gripe as much as possible as you are reading over other people’s code. That way, other engineers understand how much of a superior engineer you are.</p>
<p id="9d25" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Make sure you bring up points about the importance of maintainable code and good commenting. This further shows your dominance in the area of programming.</p>
<p id="f72b" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph=""><mark class="uq ur lw">Your code should be so well-designed that it requires no documentation. In fact, you shouldn’t document any of your code if you are a good programmer. This is just a waste of time and you need to spend your time coding and in meetings.</mark></p>
<p id="83d8" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Being able to read other people’s messy code also makes it easy to make updates when needed. This occasionally means updating code you lack experience in. For instance, we once followed a script from Powershell to Python to Perl. We had limited experience in Perl, but we still had enough context to figure out what was going on and make the changes needed.</p>
<p id="b441" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">This comes from having a decent understanding of all the code as well as being able to read the Perl scripts.</p>
<p id="339a" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Reading other people’s code makes you valuable because you can follow even over-engineered systems that might stump others.</p>
</div>
</div>
</section>
<hr class="iv ck iw ix iy iz ia ja jb jc jd je">
<section class="di dj dk dl dm">
<div class="n p">
<div class="z ab ac ae af dn ah ai">
<h1 id="7537" class="jf jg as ar jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw jx eh" data-selectable-paragraph="">2. A Sense for Bad Projects</h1>
<p id="9c82" class="ih ii as ij b ej ka il em kb in io kc er iq kd eu is ke ex iu di eh" data-selectable-paragraph="">There are many skills that take time to learn. One of the skills we believe is worth knowing is understanding what projects are not worth doing and what projects are clearly death marches.</p>
<p id="45ef" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Large companies always have many more projects going than will probably ever be completed or impactful. There are some projects that might not make any business sense (at least not to you), and there are others that are just poorly managed. This is not to say that you should cut off an idea right when you disagree with the project. However, if the stakeholders can’t properly explain what they will be doing with the end result, then perhaps the project is not worth doing.</p>
<p id="eb5f" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Also, some projects might be so focused on the technology instead of the solution that it might be clear from the beginning that there won’t be a lot of impact. This skill requires doing a lot of bad projects before you have an idea of what a bad project really is. So don’t spend too much time early on trying to discern each project.</p>
<p id="7761" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">At some point in your career, you will just have a good gut sense.</p>
</div>
</div>
</section>
<hr class="iv ck iw ix iy iz ia ja jb jc jd je">
<section class="di dj dk dl dm">
<div class="n p">
<div class="z ab ac ae af dn ah ai">
<h1 id="d7b5" class="jf jg as ar jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw jx eh" data-selectable-paragraph="">3. Avoiding Meetings</h1>
<p id="ddfa" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph=""><img decoding="async" class="pg uk s t u ho ai hy" src="https://miro.medium.com/max/2624/1*FOwBIudz9pwVbbt7uR6rqg.png" sizes="700px" srcset="https://miro.medium.com/max/276/1*FOwBIudz9pwVbbt7uR6rqg.png 276w, https://miro.medium.com/max/552/1*FOwBIudz9pwVbbt7uR6rqg.png 552w, https://miro.medium.com/max/640/1*FOwBIudz9pwVbbt7uR6rqg.png 640w, https://miro.medium.com/max/700/1*FOwBIudz9pwVbbt7uR6rqg.png 700w" alt="Image for post" width="2624" height="428">Whether you are a software engineer or data scientist, meetings are a necessity because you need to be able to get on the same page with your project managers, end-users, and clients. However, there is also a tendency for meetings to suddenly take over your entire schedule. This is why it’s important to learn how to avoid meetings that are unneeded. Maybe a better word to use is <em class="kh">manage </em>rather than avoid. The goal here is to make sure you spend your time in meetings that drive decisions and help your team move forward.</p>
<p id="73db" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">The most common method is to simply block out a two-hour block every day that is a constant meeting. Usually, most people will set up a recurring meeting at a time they find beneficial. They’ll use that as a time to catch up on their development work.</p>
<p id="38c5" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Another way to avoid meetings so you can get work done is to show up before anyone else does. Personally, we like showing up early because in general, the office is quieter. Most people that show up early are like you, just wanting to get work done so no one bugs you.</p>
<p id="35a6" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">This is important for individual contributors because our work requires times where we focus and we don’t talk to other people. Yes, there are times you might be problem-solving where you might want to work with other people. But once you get past the blocking issues, you just need to code. It’s about getting into that zone where you are constantly holding a lot of complex ideas in your head about the work you are doing. If you are constantly stopped, it can be hard to pick up where you left off.</p>
</div>
</div>
</section>
<hr class="iv ck iw ix iy iz ia ja jb jc jd je">
<section class="di dj dk dl dm">
<div class="n p">
<div class="z ab ac ae af dn ah ai">
<h1 id="60b7" class="jf jg as ar jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw jx eh" data-selectable-paragraph="">4. Github…Wait no Git?</h1>
<p id="eb9d" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph=""><img decoding="async" class="pg uk s t u ho ai hy" src="https://miro.medium.com/max/481/0*mtL55js6ZZWiax7y.png" sizes="481px" srcset="https://miro.medium.com/max/276/0*mtL55js6ZZWiax7y.png 276w, https://miro.medium.com/max/481/0*mtL55js6ZZWiax7y.png 481w" alt="Image for post" width="481" height="455"></p>
<p class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Some CS majors started using Git the day they were born. They understand every command and parameter and can run circles around professionals.</p>
<p id="074f" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Others get their first taste of Git at their first job. For them, Git is a hellish landscape of confusing commands and processes. They are never 100% sure what they are doing (there’s a reason cheat sheets are popular).</p>
<p id="a569" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">No matter what repository system your company uses, the system is both helpful if you use it correctly and a hindrance if used improperly. It doesn’t take much for a simple push or commit to turn into you spending hours trying to untangle some hodgepodge of multiple branches and forks. In addition, if you constantly forget to pull the most recent version of the repository, you will also be dealing with merge conflicts that are never fun.</p>
<p id="5da7" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">If you need to keep a Git command cheat sheet, then do it. Whatever makes your life simpler.</p>
</div>
</div>
</section>
<hr class="iv ck iw ix iy iz ia ja jb jc jd je">
<section class="di dj dk dl dm">
<div class="n p">
<div class="z ab ac ae af dn ah ai">
<h1 id="215d" class="jf jg as ar jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw jx eh" data-selectable-paragraph="">5. Writing Simple Maintainable Code</h1>
<p id="7197" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph=""><img loading="lazy" decoding="async" class="pg uk s t u ho ai hy" src="https://miro.medium.com/max/550/1*1ceZ3tCVJ-iRyS7B2THn7Q.png" sizes="auto, 550px" srcset="https://miro.medium.com/max/276/1*1ceZ3tCVJ-iRyS7B2THn7Q.png 276w, https://miro.medium.com/max/550/1*1ceZ3tCVJ-iRyS7B2THn7Q.png 550w" alt="Image for post" width="550" height="230"></p>
<p class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">One tendency younger engineers might have is to attempt to implement everything they know into one solution. There is this desire to take your understanding of object-oriented programming, data structures, design patterns, and new technologies and use all of that in every bit of code you write. You create an unnecessary complexity because it’s so easy to be overly attached to a solution or design pattern you have used in the past.</p>
<p id="6d93" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">There is a balance with complex design concepts and simple code. Design patterns and object-oriented design are supposed to simplify code in the grand scheme of things. However, the more and more a process is abstracted, encapsulated, and black-boxed, the harder it can be to debug.</p>
</div>
</div>
</section>
<hr class="iv ck iw ix iy iz ia ja jb jc jd je">
<section class="di dj dk dl dm">
<div class="n p">
<div class="z ab ac ae af dn ah ai">
<h1 id="d113" class="jf jg as ar jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw jx eh" data-selectable-paragraph="">6. Learn to Say No and Prioritize</h1>
<p id="f132" class="ih ii as ij b ej ka il em kb in io kc er iq kd eu is ke ex iu di eh" data-selectable-paragraph="">This goes for really any role, whether you are a financial analyst or a software engineer. But in particular, tech roles seem to have everyone needing something from them. If you are a data engineer, you will probably get asked to do more than just develop pipelines. Some teams will need data extracts, others will need dashboards, and others will need new pipelines for their data scientists.</p>
<p id="26fb" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Now, prioritizing and saying no might really be two different skills, but they are closely intertwined. Prioritizing means that you only spend time that has high impact for the company. Whereas saying no sometimes just means avoiding work that should be handled by a different team. They do often happen in tandem for all roles.</p>
<p id="9733" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">This can be a difficult skill to acquire as it is tempting to take on every request thrown your way. Especially if you are straight out of college. You want to avoid disappointing anyone, and you have always been provided a doable amount of work.</p>
<p id="f9d7" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">In large companies, there is always an endless amount of work. The key is only taking on what can be done.</p>
<p id="c275" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">There are a lot of skills that aren’t tested for in interviews or even always taught in colleges. Oftentimes, this is more a limitation of the environment rather than a lack of desire to expose students to problems that exist in real development environments.</p>
</div>
</div>
</section>
<hr class="iv ck iw ix iy iz ia ja jb jc jd je">
<section class="di dj dk dl dm">
<div class="n p">
<div class="z ab ac ae af dn ah ai">
<h1 id="acaa" class="jf jg as ar jh ji jj jk jl jm jn jo jp jq jr js jt ju jv jw jx eh" data-selectable-paragraph="">7. Operational Design Thinking</h1>
<p id="5787" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph=""><img loading="lazy" decoding="async" class="pg uk s t u ho ai hy" src="https://miro.medium.com/max/534/1*BnFh_-UMca79wgy7CVkHpQ.jpeg" sizes="auto, 534px" srcset="https://miro.medium.com/max/276/1*BnFh_-UMca79wgy7CVkHpQ.jpeg 276w, https://miro.medium.com/max/534/1*BnFh_-UMca79wgy7CVkHpQ.jpeg 534w" alt="Image for post" width="534" height="800"></p>
<p class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">One skill that is hard to test for in an interview and hard to replicate when you are taking courses in college is thinking through how an end-user might use your software incorrectly. We usually reference this as thinking through operational scenarios.</p>
<p id="a10c" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">However, this is just a polite way of saying you’re attempting to dummy proof code.</p>
<p id="3922" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">For instance, since much of programming is maintenance, it often means changing code that is highly tangled with other code. Even a simple alteration requires tracing every possible reference of an object, method, and/or API. Otherwise, it can be easy to accidentally break modules you don’t realize are attached. Even if you are just changing a data type in a database.</p>
<p id="e76c" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">It also includes thinking through edge cases and thinking through an entire high-level design before going into development.</p>
<p id="a225" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">As for more complex cases where you are developing new modules or microservices, it’s important to take your time and think through the operational scenarios of what you are building. Think about how future users might need to use your new module, how they might use it incorrectly, what parameters might be needed, and if there are different ways a future programmer might need your code.</p>
<p id="70df" class="ih ii as ij b ej ik il em im in io ip er iq ir eu is it ex iu di eh" data-selectable-paragraph="">Simply coding and programming is only part of the problem. It’s easy to create software that works well on your computer. But there are a lot of ways deploying code can go wrong. Once in production, it’s hard to say how code will be used and what other code will be attached to your original code. Five years from now, a future programmer might get frustrated at the limitations of your code.</p>
</div>
</div>
</section>
<p>The post <a href="http://kostacipo.stream/7-skills-of-highly-effective-programmers/">7 Skills of Highly “Effective” Programmers</a> appeared first on <a href="http://kostacipo.stream">Tech Chronicles</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://kostacipo.stream/7-skills-of-highly-effective-programmers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>10 Python Tips and Tricks You Should Learn Today</title>
		<link>http://kostacipo.stream/10-python-tips-and-tricks-you-should-learn-today/</link>
					<comments>http://kostacipo.stream/10-python-tips-and-tricks-you-should-learn-today/#respond</comments>
		
		<dc:creator><![CDATA[Majordomo]]></dc:creator>
		<pubDate>Tue, 03 Dec 2019 10:13:56 +0000</pubDate>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripts]]></category>
		<guid isPermaLink="false">http://www.kostacipo.stream/?p=1413</guid>

					<description><![CDATA[<p>&#160; Python snippets that can be taken as a reference for your daily work According to Stack Overflow, Python is the fastest growing programming language. The latest report from Forbes states that Python showed a 456-percent growth in last year. Netflix uses Python, IBM uses Python, and hundreds of other companies all use Python. Let’s [&#8230;]</p>
<p>The post <a href="http://kostacipo.stream/10-python-tips-and-tricks-you-should-learn-today/">10 Python Tips and Tricks You Should Learn Today</a> appeared first on <a href="http://kostacipo.stream">Tech Chronicles</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<blockquote>
<p class="aq ef gc gd av"><em><span style="font-size: 10pt;">Python snippets that can be taken as a reference for your daily work</span></em></p>
</blockquote>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<p id="9c0b" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">According to Stack Overflow, Python is the fastest growing programming language. The latest <a class="bo dd im in io ip" href="https://www.whatech.com/development/press-release/442278-why-developers-vote-python-as-the-best-application-programming-language" target="_blank" rel="noopener nofollow noreferrer">report from Forbes</a> states that Python showed a 456-percent growth in last year. Netflix uses Python, IBM uses Python, and hundreds of other companies all use Python. Let’s not forget Dropbox. Dropbox is also created in Python. According to <a class="bo dd im in io ip" href="https://insights.dice.com/2016/02/01/whats-hot-and-not-in-tech-skills/" target="_blank" rel="noopener nofollow noreferrer">research by Dice</a> Python is also one of the hottest skills to have and also the most popular programming language in the world based on the <a class="bo dd im in io ip" href="https://pypl.github.io/PYPL.html" target="_blank" rel="noopener nofollow noreferrer">Popularity of Programming Language Index</a>.</p>
<p id="8af1" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph=""><strong>Some of the advantages Python</strong> offers when compared to other programming languages are:</p>
<ol>
<li>&#8211; Compatible with major platforms and operating systems</li>
<li>&#8211; Many open-source frameworks and tools</li>
<li>&#8211; Readable and maintainable code</li>
<li>&#8211; Robust standard library</li>
<li>&#8211; Standard test-driven development</li>
</ol>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4>&nbsp;</h4>
<h4 id="f9d1" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">Python Tips and Tricks</h4>
<p id="f321" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">In this piece, We’ll present 10 useful code tips and tricks that can help you in your day-to-day tasks. So without further ado, let’s get started.</p>
<h4 id="5217" class="ju jv cn ar aq jw jx kn jz ko kb kp kd kq kf kr kh">1. Concatenating Strings</h4>
<p id="2b3d" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">When you need to concatenate a list of strings, you can do this using a <em class="ks">for loop</em> by adding each element one by one. However, this would be very inefficient, especially if the list is long. In Python, strings are immutable, and thus the left and right strings would have to be copied into the new string for every pair of concatenation.</p>
<p id="24ac" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">A better approach is to use the <code class="ib kt ku kv kw b">join()</code> function as shown below:</p>
<pre class="ho hp hq hr hs kx ky du"><span id="3d16" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">characters = ['p', 'y', 't', 'h', 'o', 'n']
word = "".join(characters)
print(word) <strong class="kw ld"># python</strong></span></pre>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="1162" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">2. Using List Comprehensions</h4>
<p id="47e1" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">List comprehensions are used for creating new lists from other iterables. As list comprehensions returns lists, they consist of brackets containing the expression, which is executed for each element along with the for loop to iterate over each element. List comprehension is faster because it is optimized for the Python interpreter to spot a predictable pattern during looping.</p>
<p id="a7bc" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">As an example let’s find the squares of the first five whole numbers using list comprehensions.</p>
<pre class="ho hp hq hr hs kx ky du"><span id="63bb" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">m = [x ** 2 for x in range(5)]
print(m)<strong class="kw ld"> # [0, 1, 4, 9, 16]</strong></span></pre>
<p id="61c0" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">Now let’s find the common numbers from two list using list comprehension</p>
<pre class="ho hp hq hr hs kx ky du"><span id="12d9" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">list_a = [1, 2, 3, 4]
list_b = [2, 3, 4, 5]
common_num = [a for a in list_a for b in list_b if a == b]
print(common_num) <strong class="kw ld"># [2, 3, 4]</strong></span></pre>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="a568" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">3. Iterate With <code class="ib kt ku kv kw b">enumerate()</code></h4>
<p id="4452" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">Enumerate() method adds a counter to an iterable and returns it in a form of enumerate object.</p>
<p id="79dd" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">Let’s solve the classic coding interview question named popularly as the Fizz Buzz problem.</p>
<blockquote class="le lf lg">
<p id="9622" class="iq ir cn ks is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph=""><span style="font-size: 14pt;">Write a program that prints the numbers in a list, for multiples of ‘3’ print “fizz” instead of the number, for the multiples of ‘5’ print “buzz” and for multiples of both 3 and 5 it prints “fizzbuzz”.</span></p>
</blockquote>
<pre class="ho hp hq hr hs kx ky du"><span id="e165" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">numbers = [30, 42, 28, 50, 15]
for i, num in enumerate(numbers):
    if num % 3 == 0 and num % 5 == 0:
       numbers[i] = 'fizzbuzz'
    elif num % 3 == 0:
       numbers[i] = 'fizz'
    elif num % 5 == 0:
       numbers[i] = 'buzz'
print(numbers) <strong class="kw ld"># ['fizzbuzz', 'fizz', 28, 'buzz', 'fizzbuzz']</strong></span></pre>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="a416" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">4. Using ZIP When Working with Lists</h4>
<p id="5b40" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">Suppose you were given a task to combine several lists with the same length and print out the result? Again, here is a more generic way to get the desired result by utilizing <code class="ib kt ku kv kw b">zip()</code>as shown in the code below:</p>
<pre class="ho hp hq hr hs kx ky du"><span id="1c92" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">countries = ['France', 'Germany', 'Canada']
capitals = ['Paris', 'Berlin', 'Ottawa']
for country, capital in zip(countries,capitals):
    print(country, capital) <strong class="kw ld"># France Paris 
                              Germany Berlin
                              Canada Ottawa</strong></span></pre>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="9589" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">5. Using itertools</h4>
<p id="7ffc" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">The Python <code class="ib kt ku kv kw b">itertools</code> module is a collection of tools for handling iterators. <code class="ib kt ku kv kw b">itertools</code> has multiple tools for generating iterable sequences of input data. Here I will be using <code class="ib kt ku kv kw b">itertools.combinations()</code> as an example. <code class="ib kt ku kv kw b">itertools.combinations()</code> is used for building combinations. These are also the possible groupings of the input values.</p>
<p id="8042" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">Let’s take a real world example to make the above point clear.</p>
<blockquote class="le lf lg">
<p id="6d38" class="iq ir cn ks is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph=""><span style="font-size: 14pt;">Suppose there are four teams playing in a tournament. In the league stages every team plays against every other team. Your task is to generate all the possible teams that would compete against each other.</span></p>
</blockquote>
<p id="46d5" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">Let’s take a look at the code below:</p>
<pre class="ho hp hq hr hs kx ky du"><span id="1a10" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">import itertools
friends = ['Team 1', 'Team 2', 'Team 3', 'Team 4']
list(itertools.combinations(friends, r=2)) <strong class="kw ld"># [('Team 1', 'Team 2'),      ('Team 1', 'Team 3'),  ('Team 1', 'Team 4'),  ('Team 2', 'Team 3'),  ('Team 2', 'Team 4'),  ('Team 3', 'Team 4')]</strong></span></pre>
<p id="c9e8" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">The important thing to notice is that order of the values doesn’t matter. Because <code class="ib kt ku kv kw b">('Team 1', 'Team 2')</code> and <code class="ib kt ku kv kw b">('Team 2', 'Team 1')</code> represent the same pair, only one of them would be included in the output list. Similarly we can use <code class="ib kt ku kv kw b">itertools.permutations()</code> as well as other functions from the module. For a more complete reference, check out <a class="bo dd im in io ip" href="https://medium.com/@jasonrigden/a-guide-to-python-itertools-82e5a306cdf8" target="_blank" rel="noopener noreferrer">this amazing tutorial</a>.</p>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="8668" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">6. Using Python Collections</h4>
<p id="30f1" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">Python collections are container data types, namely lists, sets, tuples, dictionary. The collections module provides high-performance datatypes that can enhance your code, making things much cleaner and easier. There are a lot of functions provided by the collections module. For this demonstration, I will be using <code class="ib kt ku kv kw b">Counter()</code> function.</p>
<p id="f158" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">The <code class="ib kt ku kv kw b">Counter()</code> function takes an iterable, such as a list or tuple, and returns a Counter Dictionary. The dictionary’s keys will be the unique elements present in the iterable, and the values for each key will be the count of the elements present in the iterable.</p>
<p id="3be5" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">To create a <code class="ib kt ku kv kw b">counter</code> object, pass an iterable (list) to <code class="ib kt ku kv kw b">Counter()</code> function as shown in the code below.</p>
<pre class="ho hp hq hr hs kx ky du"><span id="fd71" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">from collections import Countercount = Counter(['a','b','c','d','b','c','d','b'])
print(count) <strong class="kw ld"># Counter({'b': 3, 'c': 2, 'd': 2, 'a': 1})</strong></span></pre>
<p id="abcb" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">For a more complete reference, check out my <a class="bo dd im in io ip" href="https://towardsdatascience.com/a-hands-on-guide-to-python-collections-aa350cb399e3" target="_blank" rel="noopener noreferrer">python collections tutorial</a>.</p>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="59f2" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">7. Convert Two Lists Into a Dictionary</h4>
<p id="8051" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">Let’s say we have two lists, one list contains names of the students and second contains marks scored by them. Let’s see how we can convert those two lists into a single dictionary. Using the zip function, this can be done using the code below:</p>
<pre class="ho hp hq hr hs kx ky du"><span id="f095" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">students = ["Peter", "Julia", "Alex"]
marks = [84, 65, 77]
dictionary = dict(zip(students, marks))
print(dictionary) <strong class="kw ld"># {'Peter': 84, 'Julia': 65, 'Alex': 77}</strong></span></pre>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="9eae" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">8. Using Python Generators</h4>
<p id="b00e" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">Generator functions allow you to declare a function that behaves like an iterator. They allow programmers to make an iterator in a fast, easy, and clean way. Let’s take an example to explain this concept.</p>
<blockquote class="le lf lg">
<p id="5f94" class="iq ir cn ks is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph=""><span style="font-size: 14pt;">Suppose you’ve been given to find the sum of the first 100000000 perfect squares, starting with 1.</span></p>
</blockquote>
<p id="6167" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">Looks easy right? This can easily be done using list comprehension but the problem is the large inputs size. As an example let’s take a look at the below code:</p>
<pre class="ho hp hq hr hs kx ky du"><span id="07c6" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">t1 = time.clock()
sum([i * i for i in range(1, 100000000)])
t2 = time.clock()
time_diff = t2 - t1
print(f"It took {time_diff} Secs to execute this method") <strong class="kw ld"># It took 13.197494000000006 Secs to execute this method</strong></span></pre>
<p id="1710" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">On increasing the perfect numbers we need to sum over, we realize that this method is not feasible due to higher computation time. Here’s where Python Generators come to the rescue. On replacing the brackets with parentheses we change the list comprehension into a generator expression. Now let’s calculate the time taken:</p>
<pre class="ho hp hq hr hs kx ky du"><span id="0f8e" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">t1 = time.clock()
sum((i * i for i in range(1, 100000000)))
t2 = time.clock()
time_diff = t2 - t1
print(f"It took {time_diff} Secs to execute this method") <strong class="kw ld"># It took 9.53867000000001 Secs to execute this method</strong></span></pre>
<p id="e1e3" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">As we can see, time taken has been reduced quite a bit. This effect will be even more pronounced for larger inputs.</p>
<p id="eea1" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">For a more complete reference, check out my article <a class="bo dd im in io ip" href="https://towardsdatascience.com/reduce-memory-usage-and-make-your-python-code-faster-using-generators-bd79dbfeb4c" target="_blank" rel="noopener noreferrer">Reduce Memory Usage and Make Your Python Code Faster Using Generators</a>.</p>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="9d52" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">9. Return Multiple Values From a Function</h4>
<p id="bf2d" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">Python has the ability to return multiple values from a function call, something missing from many other popular programming languages. In this case the return values should be a comma-separated list of values and Python then constructs a <em class="ks">tuple</em> and returns this to the caller. As an example see the code below:</p>
<pre class="ho hp hq hr hs kx ky du"><span id="8a66" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">def multiplication_division(num1, num2):
    return num1*num2, num1/num2</span><span id="6f8e" class="kz jv cn ar kw b bj lh li lj lk ll lb r lc" data-selectable-paragraph="">product, division = multiplication_division(15, 3)
print("Product=", product, "Quotient =", division) <strong class="kw ld"># Product= 45 Quotient = 5.0</strong></span></pre>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="6f25" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">10. Using sorted() Function</h4>
<p id="6519" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">Sorting any sequence is very easy in Python using the built-in method <code class="ib kt ku kv kw b">sorted()</code>which does all the hard work for you. <code class="ib kt ku kv kw b">sorted()</code>sorts any sequence (list, tuple) and always returns a list with the elements in sorted manner. Let’s take an example to sort a list of numbers in ascending order.</p>
<pre class="ho hp hq hr hs kx ky du"><span id="13a7" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">sorted([3,5,2,1,4]) <strong class="kw ld"># [1, 2, 3, 4, 5]</strong></span></pre>
<p id="55a9" class="iq ir cn ar is b it iu iv iw ix iy iz ja jb jc jd" data-selectable-paragraph="">Taking another example, let’s sort a list of strings in descending order.</p>
<pre class="ho hp hq hr hs kx ky du"><span id="cbf4" class="kz jv cn ar kw b bj la lb r lc" data-selectable-paragraph="">sorted(['france', 'germany', 'canada', 'india', 'china'], reverse=True) <strong class="kw ld"># ['india', 'germany', 'france', 'china', 'canada']</strong></span></pre>
</div>
</div>
</section>
<section class="fd fe ff fg fh">
<div class="n p">
<div class="ac ae af ag ah fi aj ak">
<h4 id="c1ec" class="ju jv cn ar aq jw jx jy jz ka kb kc kd ke kf kg kh">Conclusions</h4>
<p id="9d84" class="iq ir cn ar is b it ki iv kj ix kk iz kl jb km jd" data-selectable-paragraph="">In this article, We&#8217;ve presented 10 Python tips and tricks that can be used as a reference in your day-to-day work. We hope you enjoyed this article.</p>
</div>
</div>
</section>
<p>&nbsp;</p>
<p>The post <a href="http://kostacipo.stream/10-python-tips-and-tricks-you-should-learn-today/">10 Python Tips and Tricks You Should Learn Today</a> appeared first on <a href="http://kostacipo.stream">Tech Chronicles</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://kostacipo.stream/10-python-tips-and-tricks-you-should-learn-today/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
