avatarHaider Imtiaz

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

8606

Abstract

an class="hljs-meta"># c 3</span> <span class="hljs-meta"># d 4</span></pre></div><h1 id="23a8">Final Thoughts</h1><p id="030d">Glad you reached the end of this article and I hope you find it interesting and useful. Also, share❤️ this article with your Pythoneer Friends. <b>Happy Coding!</b></p><p id="4428"><b>🚨Hi </b>— if you want to Explore Medium Stuff then consider supporting me and your other favorite Writers by <a href="https://codedev101.medium.com/membership"><b>signing up for a membership</b></a>. Believe me, it only costs $5 per month and you can access unlimited stories of medium and daily interesting Medium digest.</p><p id="1bf8"><b><i>Becoming a Member of Medium Thanks! 👇</i></b></p><div id="74de" class="link-block"> <a href="https://codedev101.medium.com/membership"> <div> <div> <h2>Join Medium with my referral link — Haider Imtiaz</h2> <div><h3>As a Medium member, a portion of your membership fee goes to writers you read, and you get full access to every story…</h3></div> <div><p>codedev101.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*nXT5pzhQV3qgGMhs)"></div> </div> </div> </a> </div><p id="bbf5"><b><i>Never Stop Learning, Here is your daily dose of my programming articles below, hope you like them also.</i></b></p><div id="2df2" class="link-block"> <a href="https://python.plainenglish.io/7-hidden-hacks-of-python-you-probably-never-used-32638811877e"> <div> <div> <h2>7 Hidden Hacks of Python You Probably Never Used</h2> <div><h3>Some Lesser-Know Python Snippets Codes</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*MZO9BzuFsRD_bs1GDyP9iA.jpeg)"></div> </div> </div> </a> </div><div id="2c2b" class="link-block"> <a href="https://python.plainenglish.io/13-python-features-most-programmers-never-used-28a6578abe00"> <div> <div> <h2>13 Python Features Most Programmers Never Used</h2> <div><h3>A list of incredible features most programmers don’t know about.</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*8ixphH0JGZ_Uyf7lbwVqOg.jpeg)"></div> </div> </div> </a> </div><div id="d0e9" class="link-block"> <a href="https://python.plainenglish.io/9-cool-python-project-ideas-for-programmers-c7252c76db34"> <div> <div> <h2>9 Cool Python Project Ideas for Programmers</h2> <div><h3>A list of cool and fun Python projects that you can finish this weekend.</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*yAxSVwUnewuFmiYweAHqgw.jpeg)"></div> </div> </div> </a> </div><div id="8eec" class="link-block"> <a href="https://python.plainenglish.io/hidden-features-of-python-that-you-have-probably-never-heard-of-47af1e8abee2"> <div> <div> <h2>Python Hidden Features That You Probably Never Heard Of</h2> <div><h3>Lesser-known Python Features, Tips, and Tricks</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*NKDm9kgiBXLl2SNElFmRBg.jpeg)"></div> </div> </div> </a> </div><div id="a7de" class="link-block"> <a href="https://python.plainenglish.io/12-pro-tips-and-tricks-for-python-developers-40fa4a618c76"> <div> <div> <h2>12 Pro Tips and Tricks for Python Developers</h2> <div><h3>A list of tips and tricks to code faster and more efficiently in Python.</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*cK7HAxX1EEmeQGaOEqScIA.jpeg)"></div> </div> </div> </a> </div><div id="e35e" class="link-block"> <a href="https://python.plainenglish.io/13-python-advanced-code-snippets-for-everyday-problems-fb9874ea0b18"> <div> <div> <h2>13 Python Advanced Code Snippets for Everyday Problems</h2> <div><h3>An article on using advanced codes to make everyday Python problems easier.</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*1AktzTtx2ZOH1kb8yv7Piw.jpeg)"></div> </div> </div> </a> </div><div id="db0d" class="link-block"> <a href="https://python.plainenglish.io/13-python-features-most-programmers-never-used-28a6578abe00"> <div> <div> <h2>13 Python Features Most Programmers Never Used</h2> <div><h3>A list of incredible features most programmers don’t know about.</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*8ixphH0JGZ_Uyf7lbwVqOg.jpeg)"></div> </div> </div> </a> </div><div id="4074" class="link-block"> <a href="https://python.plainenglish.io/20-python-code-snippets-for-everyday-programming-problems-339346a6f996"> <div> <div> <h2>20 Python Code Snippets For Everyday Programming Problems</h2> <div><h3>Level up your programming skills with these useful Python code snippets</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*RIzNp-TiXtc4-OpvCiU8-w.jpeg)"></div> </div> </div> </a> </div><div id="2e66" class="link-block"> <a href="https://python.plainenglish.io/9-free-online-resume-builders-for-programmers-1235f014d3e1"> <div> <div> <h2>9 Free Online Resume Builders For Programmers</h2> <div><h3>Here are some free resume builders that you can use to build your resume in no time.</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*TsYT3ECNYEzRVN8Owq8nlQ.png)"></div> </div> </div> </a> </div><div id="ccf1" class="link-block"> <a href="https://python.plainenglish.io/17-killer-websites-that-every-programmer-should-visit-119805fd7adc"> <div> <div> <h2>17 Killer Websites That Every Programmer should Visit</h2> <div><h3>98% of programmers and developers don’t know about these websites.</h3></div> <div><p>python.plainenglish.io</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*zYBmNB6I0etS6Id2c7Xfdw.jpeg)"></div> </div> </div> </a> </div><div id="eafc" class="link-block"> <a href="https://python.plainenglish.io/build-modern-gui-in-python-using-pyqt5-framework-d3398beeb555"> <div> <div> <h2>Build Modern GUI in Python using PyQt5 Framework</h2> <div><h3>Learn to develop Modern Design GUI Program in Python using PyQt5 Framework</h3></div> <div><p>python.plainenglish.io</p></div>

Options

          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*20gmIHZKX_sPY5J-6QsiJA.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><div id="fc26" class="link-block">
      <a href="https://python.plainenglish.io/20-extremely-useful-python-one-liners-you-must-know-6c5f3d9c875a">
        <div>
          <div>
            <h2>20 Extremely Useful Python One-Liners You Must Know</h2>
            <div><h3>Useful Python one-liner Snippets to solve any coding problem in just one line</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*WShewTxsX-dHks6AXgCd9g.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><div id="04d6" class="link-block">
      <a href="https://python.plainenglish.io/9-easy-ways-to-earn-money-while-learning-python-21e1f680a6dd">
        <div>
          <div>
            <h2>9 Easy Ways To Earn Money While Learning Python</h2>
            <div><h3>Don’t stay in bed unless you can make money in bed</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*LJN8ggsPDQKTIHcIlhWrFg.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><div id="5e9a" class="link-block">
      <a href="https://python.plainenglish.io/22-useful-snippets-to-code-like-a-pro-in-python-1d0dcaacac69">
        <div>
          <div>
            <h2>22 Useful Snippets to Code like a Pro in Python</h2>
            <div><h3>Get vowels, finding anagrams, sorting dictionary, n times string, byte sizing, filtering, etc. You will learn much more…</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*8lhZBBja11Pf4_K1IYCj-Q.png)"></div>
          </div>
        </div>
      </a>
    </div><div id="1f58" class="link-block">
      <a href="https://python.plainenglish.io/top-python-tricks-that-will-boost-your-skills-c55e8268ca5f">
        <div>
          <div>
            <h2>Top Python Tricks That Will Boost Your Skills</h2>
            <div><h3>Most used tricks that will boost your Python programming skills.</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*3Fr1uaEJfdad-mVLbPMaIg.png)"></div>
          </div>
        </div>
      </a>
    </div><div id="01db" class="link-block">
      <a href="https://python.plainenglish.io/hidden-features-of-python-that-you-have-probably-never-heard-of-47af1e8abee2">
        <div>
          <div>
            <h2>Python Hidden Features That You Probably Never Heard Of</h2>
            <div><h3>Lesser-known Python Features, Tips, and Tricks</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*NKDm9kgiBXLl2SNElFmRBg.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><div id="0197" class="link-block">
      <a href="https://python.plainenglish.io/22-helpful-python-tips-and-tricks-for-beginners-43c4a8f56a1c">
        <div>
          <div>
            <h2>Useful Tips and Tricks for Python Programmers</h2>
            <div><h3>Super Awesome Tips and Tricks for better and Pro coding in Python you should know as a Programmer.</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*Ro7Fogu5keiL5jA4.png)"></div>
          </div>
        </div>
      </a>
    </div><div id="b427" class="link-block">
      <a href="https://python.plainenglish.io/17-python-tips-and-tricks-to-boost-your-coding-skills-5e14054001b2">
        <div>
          <div>
            <h2>17 Python Tips and Tricks to Boost your Coding Skills</h2>
            <div><h3>Make your life easier with these Top Python Tips and Tricks</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*Q5zOL3rCGnljaBnrwrpr0w.png)"></div>
          </div>
        </div>
      </a>
    </div><div id="a793" class="link-block">
      <a href="https://python.plainenglish.io/from-zero-to-hero-in-python-in-just-10-minutes-83064ffd5aee">
        <div>
          <div>
            <h2>From Zero to Hero in Python in Just 10 minutes</h2>
            <div><h3>Everything you need to learn to go from zero to hero in Python.</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*uogTxM0a-lVa__VkjFBjew.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><div id="1814" class="link-block">
      <a href="https://python.plainenglish.io/25-programming-jokes-to-make-you-lol-8bf793eb2a52">
        <div>
          <div>
            <h2>25 Programming Jokes To Make You LOL</h2>
            <div><h3>Some funny programming jokes to make you smile and laugh</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*x3fGnT5-vln_l_OK)"></div>
          </div>
        </div>
      </a>
    </div><div id="5e8c" class="link-block">
      <a href="https://python.plainenglish.io/top-python-shortcuts-c0345d5a48ec">
        <div>
          <div>
            <h2>Top Python Shortcuts</h2>
            <div><h3>15 Python Tips and Tricks that make your life easier</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*-IYcE6-YJTX_brw67C6aRA.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><div id="3e27" class="link-block">
      <a href="https://python.plainenglish.io/12-python-interesting-facts-that-you-might-not-know-72dcb90b8ea">
        <div>
          <div>
            <h2>12 Python Interesting Facts That You Might Not Know</h2>
            <div><h3>12 Facts I Bet You Didn’t Know About Python</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*X_xqpHrzODjl8K4YMOGAuQ.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><div id="65cb" class="link-block">
      <a href="https://python.plainenglish.io/python-snippets-you-should-learn-today-e796456bd6db">
        <div>
          <div>
            <h2>Python Snippets You Should Learn Today</h2>
            <div><h3>Top Python snippets that save your valuable time and make your life easier.</h3></div>
            <div><p>python.plainenglish.io</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*fqvnEW_Ixk3vfLQu44xjRA.jpeg)"></div>
          </div>
        </div>
      </a>
    </div><p id="b942"><i>More content at <a href="https://plainenglish.io/"><b>PlainEnglish.io</b></a>. Sign up for our <a href="http://newsletter.plainenglish.io/"><b>free weekly newsletter</b></a>. Follow us on <a href="https://twitter.com/inPlainEngHQ"><b>Twitter</b></a> and <a href="https://www.linkedin.com/company/inplainenglish/"><b>LinkedIn</b></a>. Join our<b> <a href="https://discord.gg/GtDtUAvyhW">community Discord</a></b>.</i></p></article></body>

7 Python Tips and Tricks You Probably Don’t Know

Most Common and Notorious Python Tips for Pro Codding

Designed by wayhomestudio on Freepik

Python is notorious and amazing but do you know some time-saving Tips for Python that will improve your coding style in Python. In this article, we will look over the 7 Tips and tricks in Python that you Probably don’t know. So bookmark the article and let's dive into it.

1. Count the Frequency

Now you don’t need to use loops to count the frequency of every element in the list. You can do it with Python built-in module counter. Moreover, you can also count for specific elements too. Check the example code below.

# Count Frequency
import collections
lst = [1,2,3,2,2,4,4,4,5,6,7,7,7,5,3]
counter=collections.Counter(lst)
print(counter)
#output
# Counter({2: 3, 4: 3, 7: 3, 3: 2, 5: 2, 1: 1, 6: 1})

2. Fast way to Format String

You probably use the format() function to format your string or % method. But do you know there is a faster way to format your string without writing these lengthy methods? Check out the example code below:

# Fast way to Format String
w1 = "something"
w2 = "Daily"
data = f"Code is {w1} we should do {w2}"
print(data) # Code is something we should do Daily

3. Read CSV without Pandas

Now you no longer need Pandas module to read and write CSV. You can use the Python built-in module to do the same stuff as shown below:

# CSV Reading
import csv
with open('test.csv', 'r') as file:
    r = csv.reader(file)
    for row in r:
        print(row)

4. Get File Name From Path

This awesome tip will help you get the file name from the path. This will be handy for someone who needs to extract the name of the file from a full path. Check out the example code below:

# Get file name from Path
import os
filepath =  "/path/to/file.txt"
filename = os.path.basename(filepath)
print(filename) # file.txt
# file name without extension
print(filename.split(".")[0]) # file

5. Magic of Regular Expression

Regular expression is an awesome tip for extracting, matching, and searching a specific string in Text data. Below I mention an example code for extracting phone numbers from raw text data:

# Magic of Regular Expression
import re
# example 1
phn = "jajdasko;askj9234989835kfpwek"
r = re.findall("[0-9]", phn)
print("".join(r)) # 0234989835

6. Hidden Functions of Print

Do you know the Python print() method had some arguments functions too? In the below example code I mention two of the common Python argument functions you must see.

# Hidden Python Func
# hidden 1
print("hello", end=" ")
print("world")
#output:
#hello world
#hidden 2
print("Python", "is", "somthing", "different", sep="#")
#output
#Python#is#somthing#different

7. Iterate Pair of List

This simple tip and trick will help you iterate two pairs of lists at the same time. Check out the below code:

# iterating pair of String
lst1 = ['a', 'b', 'c', 'd']
lst2 = ['1', '2', '3', '4']
for x, y in zip(lst1, lst2):
    print(x, y)
# output
# a 1
# b 2
# c 3
# d 4

Final Thoughts

Glad you reached the end of this article and I hope you find it interesting and useful. Also, share❤️ this article with your Pythoneer Friends. Happy Coding!

🚨Hi — if you want to Explore Medium Stuff then consider supporting me and your other favorite Writers by signing up for a membership. Believe me, it only costs $5 per month and you can access unlimited stories of medium and daily interesting Medium digest.

Becoming a Member of Medium Thanks! 👇

Never Stop Learning, Here is your daily dose of my programming articles below, hope you like them also.

More content at PlainEnglish.io. Sign up for our free weekly newsletter. Follow us on Twitter and LinkedIn. Join our community Discord.

Python
Python3
Programming
Coding
Software Development
Recommended from ReadMedium