• TypeError - dict_values is not subscriptable
    09 April

    TypeError: ‘dict_values’ Object Is Not Subscriptable

    Reproducing TypeError: ‘dict_values object is not subscriptable When you try to access the dict_values object through index, the error will raise stating TypeError: 'dict_values' object is not subscriptable. Here is the example below. [crayon-661e70073ddaf950640574/] [crayon-661e70073ddb8132584052/] Convert dict_values object to list To resolve TypeError: 'dict_values object is not subscriptable, convert dict_values object to list before accessing […]

  • Sleep for milliseconds in python
    17 March

    Python Sleep Milliseconds(ms) with examples

    💡 Outline You can use time.sleep() method to sleep for milliseconds in Python. If you want to delay python program by 500 ms, then you need to pass 0.5 as parameter to sleep method. [crayon-661e70073fc0c403850979/] 1. Introduction Sometimes, the execution of a program needs to be suspended or paused for a given time. This is […]

  • Create Empty Array in Python
    13 March

    Create Empty Array in Python

    Creating an Empty Array in Python Before moving towards various solutions for creating an empty array in Python, we must understand what an empty array means. It means a collection of items with a particular data type containing no items or elements. We can use different ways to create an empty one-dimensional, two-dimensional and multi-dimensional […]

  • Remove Non-alphanumeric Characters in Python
    11 March

    Remove Non-alphanumeric Characters in Python

    1. Overview Non-alphanumeric characters are those that are not letters or numbers, such as punctuation marks, symbols, spaces, or special characters. Sometimes, we may want to remove these characters from String in Python, for example, to clean user input, extract data etc. 2. Introduction to Problem Let’s say we have a string: [crayon-661e700740d40044798231/] As we […]

  • Read File without newline in Python
    08 March

    Read File without Newline in Python

    Read File without NewLine in Python In Python, there are multiple ways to read a file without new lines, but before diving into those methods, let’s look at the .txt file we will use for this article. [crayon-661e700741a0d707005127/] You can follow along using the file.txt or your own file. Use read() and replace() Methods To […]

  • Print without space in Python
    07 March

    Print Without Space in Python

    Using the sep Parameter Use the sep parameter to print without space in Python. [crayon-661e700741b77400288429/] [crayon-661e700741b7a490335048/] Python’s print() method displays a specified message or variables’ value on the screen or other standard output devices. Here, the message means a string or an object or object that will be transformed into a string before writing to […]

  • Check if Variable is empty in Python
    06 March

    Check if Variable is Empty in Python

    1. Introduction Checking if a variable is empty in Python is a fundamental task, especially in data validation or conditional logic. For example, in a user registration form, checking if the username field is empty is crucial before processing the form. Our goal to determine whether a variable like username contains any data or is […]

  • Convert List to Integer in Python
    28 February

    Convert List to Integer in Python

    Using for Loop To convert the entire list into one integer in Python: Create a list having integer-type elements. Declare and initialize a variable with 0; it will be used to hold the final integer value. Use the for loop to iterate over the list items. In each iteration: multiply the variable created in the […]

  • Get first n elements of lists in Python
    20 February

    Get First n Elements of List in Python

    Using List slicing Use list slicing to get first n elements of List in Python. Here’s an example: [crayon-661e700742b25237976257/] [crayon-661e700742b29529061861/] In the above example, list slicing is used to get a list’s first n elements. As we can see, a list was defined as my_list with 6 elements [10, 20, 30, 40, 50, 60]. And […]