
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

152 Views
When it is required to remove tuples with difference greater than K, use the abs() method.Below is a demonstration of the same −Examplemy_tuple = [(41, 18), (21,57), (39, 22), (23, 42), (22, 10)] print("The tuple is :") print(my_tuple) K = 20 my_result = [element for element in my_tuple if abs(element[0] - element[1])

4K+ Views
When it is required to remove dictionary from a list of dictionaries if a particular value is not present, a simple iteration and the ‘del’ operator is used.ExampleBelow is a demonstration of the same −my_list = [{"id" : 1, "data" : "Python"}, {"id" : 2, "data" : "Code"}, {"id" : 3, "data" : "Learn"}] print("The list is :") print(my_list) for index in range(len(my_list)): if my_list[index]['id'] == 2: del my_list[index] break print("The result is :") print(my_list)OutputThe list ... Read More

298 Views
When it is required to get all the occurrences of a substring from the list of strings, a simple list comprehension and the ‘startswith’ method is used.ExampleBelow is a demonstration of the same −my_string = "Is python fun to learn?" print("The list is :") print(my_string) substring = "pyt" print("The substring is :") print(substring) my_result = [i for i in range(len(my_string)) if my_string.startswith(substring, i)] print("The result is :") print(my_result)OutputThe list is : Is python fun to learn? The substring is : pyt The result is : [3]ExplanationA string is defined and is displayed on the console.Another substring ... Read More

183 Views
When it is required to extract strings which have successive alphabets in alphabetical order, a simple iteration, and the ‘ord’ method for Unicode representation is used.ExampleBelow is a demonstration of the same −my_list = ["python", 'is', 'cool', 'hi', 'Will', 'How'] print("The list is :") print(my_list) my_result = [] for element in my_list: for index in range(len(element) - 1): if ord(element[index]) == ord(element[index + 1]) - 1: my_result.append(element) break print("The result ... Read More

178 Views
When it is required to test for desired string lengths, a simple iteration, and the ‘len’ method is used.ExampleBelow is a demonstration of the same −my_list = ["python", 'is', 'fun', 'to', 'learn', 'Will', 'how'] print("The list is :") print(my_list) length_list = [6, 2, 3, 2, 5, 4, 3] my_result = True for index in range(len(my_list)): if len(my_list[index]) != length_list[index]: my_result = False break print("The result is :") if(my_result == True): print("All the strings are of required lengths") else: print("All the strings are not of required lengths")OutputThe list is : ... Read More

303 Views
When it is required to sort a list of strings based on the number of unique characters, a method is defined that uses a ‘set’ operator, the ‘list’ method and the ‘len’ method.ExampleBelow is a demonstration of the same −def my_sort_func(my_elem): return len(list(set(my_elem))) my_list = ['python', "Will", "Hi", "how", 'fun', 'learn', 'code'] print("The list is : ") print(my_list) my_list.sort(key = my_sort_func) print("The result is :") print(my_list)OutputThe list is : ['python', 'Will', 'Hi', 'how', 'fun', 'learn', 'code'] The result is : ['Hi', 'Will', 'how', 'fun', 'code', 'learn', 'python']ExplanationA method named ‘my_sort_func’ is defined, that takes ... Read More

2K+ Views
When it is required to extract words starting with vowel from a list, a simple iteration, a flag value and the ‘startswith’ method are used.Below is a demonstration of the same −Example:my_list = ["abc", "phy", "and", "okay", "educate", "learn", "code"] print("The list is :") print(my_list) my_result = [] my_vowel = "aeiou" print("The vowels are ") print(my_vowel) for index in my_list: my_flag = False for element in my_vowel: if index.startswith(element): my_flag = True ... Read More

184 Views
When it is required to print rows where all its elements’ frequency is greater than K, a method is defined that takes two parameters, and uses ‘all’ operator and iteration to give the result.Below is a demonstration of the same −Exampledef frequency_greater_K(row, K) : return all(row.count(element) > K for element in row) my_list = [[11, 11, 32, 43, 12, 23], [42, 14, 55, 62, 16], [11, 11, 11, 11], [42, 54, 61, 18]] print("The tuple is :") print(my_list) K = 1 print("The value of K is :") print(K) my_result = [row for row in my_list if frequency_greater_K(row, ... Read More

101 Views
When it is required to repeat elements at custom indices, a simple iteration, enumerate attribute, the ‘extend’ method and the ‘append’ method are used.Below is a demonstration of the same −Examplemy_list = [34, 56, 77, 23, 31, 29, 62, 99] print("The list is :") print(my_list) index_list = [3, 1, 4, 6] my_result = [] for index, element in enumerate(my_list): if index in index_list: my_result.extend([element, element]) else : my_result.append(element) print("The result is :") print(my_result)OutputThe list is : [34, 56, 77, 23, 31, 29, ... Read More

2K+ Views
When it is required to find the Fibonacci sequence using the method of recursion, a method named ‘fibonacci_recursion’ is defined, that takes a value as parameter. It is called again and again by reducing the size of the input.Below is a demonstration of the same:Exampledef fibonacci_recursion(my_val): if my_val