How To Find All Occurrences Of A Substring? In Python

In this Tutorial, we will learn How To Find All Occurrences Of A Substring from a String? In Python, we can find All Occurrences Of A Substring by using some inbuild functions which are string.rfind(), String.find(), and String.find_all(). Different Ways To Finding Occurrences Of A Substring There are a number of ways to find the … Read more

How Immutable Is Different from Mutable Types, In python Programming

Mutable are those which could be edited after it is defined for example list whose elements can be edited even after defining, whereas in case of immutable we can not edit them for example String. What is Mutable? Mutuable are those data Types that can be edited after Declaration For example once a datatype is … Read more

What is Ordered Dictionary and Default Dictionary in Python?

What is Ordered Dictionary and Default Dictionary in Python?

Dictionary in Python Dictionary is an unordered collection of mutable values indexed by unique keys. Values in a dictionary can be of any datatype, mutable and can be duplicated, whereas keys can’t be repeated and are immutable. Dictionaries are just like map(), storing, and retrieving elements by referencing a key. As dictionaries are referenced by … Read more

Some Basic Python Tuple Programs-2

Some Basic Python Tuple Programs-2

Python Program to check if a tuple and a list are identical tuple = (9, 8, 7, 6, 5) list = [9, 8, 7, 6, 5] #using loop flag1 = True for i in range(0, len(tuple)): if tuple[i] != list[i]: flag1 = False break if flag1: print(f”{tuple} and {list} are identical”) else: print(f”{tuple} and {list} … Read more

Some Basic Python List Programs-3

Some Basic Python List Programs-3

Python program to remove duplicates from a list list1 = [2, 6, 9, 8, 4, 8, 6, 6, 5, 7, 2, 4] #using list comprehension list2 = [] [list2.append(ele) for ele in list1 if ele not in list2] print(list2) #Output: [2, 6, 9, 8, 4, 5, 7] #using list comprehension and enumerate() list3 = [ele … Read more

Some Basic Python String Programs-3

Some Basic Python String Programs-3

Python program to move Word to Rear-end str1 = “Beta Python: Python for U ” word = “Python” #using slicing and find() str2 = str1[:str1.find(word)] + str1[str1.find(word) + len(word):] + word print(str2) #Output: Beta : Python for U Python #using replace() str3 = str1.replace(word,””) + word print(str3) #Output: Beta : for U Python Slicing extracts … Read more

Some Basic Python Tuple Programs-3

Some Basic Python Tuple Programs-3

Python program to find the minimum and maximum value in a list of tuples tuple_list = [(6, 5), (3, 8), (1, 6), (4, 7), (3, 1)] ele1 = tuple(map(max, zip(*tuple_list))) ele2 = tuple(map(min, zip(*tuple_list))) print(ele1, el2) #Output: (6, 8) (1, 1) The built-in max() function returns the largest element in an iterable. The built-in min() … Read more

Some Basic Python String Programs-4

Some Basic Python String Programs-4

Python program to check if the string is ASCII string = “Beta Python: Python for U” #using all() and ord() if all(ord(ch) < 128 for ch in string): print(f”{string} is ASCII string”) else: print(f”{string} is not an ASCII string”) #Output: Beta Python: Python for U is ASCII string #using lambda and encode() if lambda ch: … Read more

Some Basic Python Dictionary Programs-1

Some Basic Python Dictionary Programs-1

Dictionary Dictionary is an unordered collection of mutable values indexed by unique keys. Values in a dictionary can be of any datatype, mutable and can be duplicated, whereas keys can’t be repeated and are immutable. Python program to extract values of Particular Key in Nested Values dict = {“Uppercase” : {1 : “A”, 2 : … Read more

Some Basic Python String Programs-2

Some Basic Python String Programs

Python Program to split a string into groups of n consecutive characters string = “Beta Python: Python for U” n = 5 split_string = [(string[ch:ch+n]) for ch in range(0, len(string), n)] #list comprehension print(split_string) #Output: [‘Beta ‘, ‘Pytho’, ‘n: Py’, ‘thon ‘, ‘for U’] List comprehension is a compact method that defines a list and … Read more

%d bloggers like this: