When it is required to test if all elements are unique in columns of a matrix, a simple iteration and a list comprehension along with the ‘set’ operator are used.Below is a demonstration of the same −Example Live Demomy_list = [[11, 24, 84], [24, 55, 11], [7, 11, 9]] print("The list is :") print(my_list) my_result = True for index in range(len(my_list[0])): column = [ele[index] for ele in my_list] if len(list(set(column ))) != len(column ): my_result = False break if(my_result == True): print("All columns are unique") else: ... Read More
When it is required to remove characters, which are greater than ‘K’, a simple iteration is used along with the ‘ord’ (Unicode representation) method.Below is a demonstration of the same −Example Live Demomy_list = ["python", "is", "easy", "to", "learn"] print("The list is :") print(my_list) K = 9 print("The value of K is ") print(K) my_result = [] for element in my_list: result_string = '' for sub in element: if (ord(sub) - 97
When it is required to check if any list element is present in a tuple or not, a Boolean value and a simple iteration are used.Below is a demonstration of the same −Example Live Demomy_tuple = (14, 35, 27, 99, 23, 89, 11) print("The tuple is :") print(my_tuple) my_list = [16, 27, 88, 99] print("The list is :") print(my_list) my_result = False for element in my_list: if element in my_tuple : my_result = True break print("The result is :") if(my_result == True): print("The element is present in the ... Read More
When it is required to sort rows of a matrix by custom element count, a method is defined that uses the list comprehension and ‘len’ method to find the output.Below is a demonstration of the same −Example Live Demodef get_count_matrix(my_key): return len([element for element in my_key if element in custom_list]) my_list = [[31, 5, 22, 7], [85, 5], [9, 11, 22], [7, 48]] print("The list is :") print(my_list) custom_list = [31, 85, 7] my_list.sort(key=get_count_matrix) print("The resultant list is :") print(my_list)OutputThe list is : [[31, 5, 22, 7], [85, 5], [9, 11, 22], [7, 48]] The ... Read More
When it is required to filter rows with a specific pair sum, a method is defined. It checks to see if elements in a specific index is equal to key, and returns output based on this.Below is a demonstration of the same −Example Live Demodef find_sum_pair(val, key): for index in range(len(val)): for ix in range(index + 1, len(val)): if val[index] + val[ix] == key: return True return False my_list = [[71, 5, 21, 6], [34, 21, 2, 71], [21, 2, 34, 5], [6, 9, ... Read More
Datatype is the declaration of memory location or variable. Data can be of different types and some of the examples of data types in C language are as follows −Integers, rational numbers, whole numbers, real numbers, complex numbers, vectors, characters etc.Coming to the machine hardware, the data is everything encoded as a string of binary digits 0 and 1 of finite length. In the machines, the integer data is processed in the arithmetic logic unit (ALU) and fractional data is processed in the floating-point unit (FPU). This gets reflected in the built-in or primitive data types of a high-level language.Built-in ... Read More
Computer is an electronic device which can used to store data and to perform operations, based on the size of computer, the computer may be divided into four types they are −Micro-computer (small)Mini-computer (medium)Mainframe computer (large)Supercomputer (very large)Micro-computerThe CPU used in micro-computer is microprocessor, it originated in the late 1970’s. The first micro-computer is around 8-bit microprocessor chips.The chip with 8-bit can retrieve data/instruction from storage, process and manipulate at a time. The cost of micro-computers is economical and are friendly in use. Personal computers (PCs) can fall into this category.Mini-computerIt originated in the 1960’s. Initially the mini-computers were 8 ... Read More
Linked lists use dynamic memory allocation and are collection of nodes.Nodes have two parts which are data and link.Types of Linked ListsThe types of linked lists in C programming language are as follows −Single / Singly linked lists.Double / Doubly linked lists.Circular single linked list.Circular double linked list.Double linked listThe diagram given below depicts the representation of double linked list.ExampleFollowing is the C program to insert a node at any position using double linked list − Live Demo#include #include struct node { int num; struct node * preptr; struct node * nextptr; }*stnode, *ennode; void DlListcreation(int ... Read More
Linked lists use dynamic memory allocation and are collection of nodes.Nodes have two parts which are data and link.Types of Linked ListsThe types of linked lists in C programming language are as follows −Single / Singly linked listsDouble / Doubly linked listsCircular single linked listCircular double linked listSingle linked listThe diagram given below depicts the representation of single linked list.ExampleFollowing is the C program to display the numbers in reverse order by using the single linked list − Live Demo#include #include struct node { int num; struct node *nextptr; }*stnode; void createNodeList(int n); void reverseDispList(); void displayList(); ... Read More
In order to find the trailing zero in a given factorial, let us consider three examples as explained below −Example 1Input − 4Output − 0Explanation − 4! = 24, no trailing zero.Factorial 4! = 4 x 3 x 2x 1 = 24. No trailing zero i.e. at 0’s place 4 number is there.Example 2Input − 6Output − 1Explanation − 6! = 720, one trailing zero.Factorial 6! = 6 x 5 x 4 x 3 x 2 x 1 = 720, one trailing zero, because at 0’s place 0 number is there.Example 3The input is as follows −n = 4 n ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP