Reverse a word in python | Letters in word and Sentences

It a very easy to Reverse words in a string python, you have to first Separate each word, then Reverse the word separated list and in the last join each word with space. For all this step you needed a split(), join() , reversed() function and list data structure. Algorithm of reverse words in a sentence Read More…


Reverse a number(integer) in python | Loop or Recursion

Numbers can be reversed in Python using different methods. Like loop or Recursion can use to reverse a number in python. let us take a look at the Python program to implement the same. Ways to reverse a number in Python Using a Loop Using Recursion Python programs to reverse a number Let’s see the both examples: Read More…


Python slice Function |::-1 shorthand, (Array, List, Tuple, String)

Python slice function returns a slice object that can use used to slice strings, lists(Array), tuple, etc. Means slice object is used to specify how to slice a sequence like strings, lists, tuples. Syntax

Parameters start  – The slicing of the object starts. Optional and Default is NONE. stop – The slicing stops at index stop -1 (last Read More…


Python list slice | Get specific sets of sub-elements Array

As you know Python List is a collection that is ordered and changeable. if you don’t know then you must read the first Python List tutorial. Python List Slicing is a way to get a range of items in a list. Note: List are index from 0 to size-1, with a step of 1. Syntax A syntax Read More…


Python slice string Function| Get a range of characters (SubString)

You can get a range of characters(substring) by using the slice function. Python slice() function returns a slice object that can use used to slice strings, lists, tuples. You have to Specify the parameters- start index and the end index, separated by a colon, to return a part of the string. Syntax

Parameters start Read More…


Python reverse string | Using loop, recursion, stack, slice, reversed

The string is a sequence of character data. There is no built-in function to reverse a string. But you can use slice, loop, recursion, reversed, join, etc function to reverse a string in python. Way to Python reverse string Loop – for-loop slice Recursion reversed with join() stack Example of Python reverse string We will see Read More…


Python sort dictionary by Value/Key | Ascending & Descending order examples

You can sort a dictionary in python by using the sorted() function. it is actually possible to do a “sort by dictionary values”.  You could use: sorted(d.items(), key=lambda x: x[1]) This will sort the dictionary by the values of each entry within the dictionary from smallest to largest. Python sort dictionary by value Example Python Read More…


Python sort string | alphabetically letters ascending/descending order

You can sort string in python using “join() + sorted()” and “sorted() + reduce() + lambda” method combinations. String can sort the letter/characters in ascending or descending alphabetically order. Example of Python sort string Let’ see the both ways example program. 1. Using join() + sorted() First sorted list of characters and then join the Read More…


Python sort list of tuples | descending, first, second, last, multiple elements, value, alphabetically

Python sort list of tuples using sort method needed key which sorts lists in place. And also offers a convenient way to sort tuples based on the index of tuple elements. You can sort list of tuples by first and second element by using index or values. tup[0] to sort on first tuple element tup[1] to sort on Read More…


Difference between sort vs sorted Python Function

You can sort the list using sort() or sorted() Python function. You must be thinking about then what is the difference sort() and sorted() funciton. The main difference between the list sort() and sorted() Python function is that the sort() function will modify the list it is called on. The sorted() function will create a new list containing a sorted version of Read More…