In this article we develop a program to calculate the frequency of each element present in a list.Using a dictionaryHere we capture the items as the keys of a dictionary and their frequencies as the values.Example Live Demolist = ['a', 'b', 'a', 'c', 'd', 'c', 'c'] frequency = {} for item in list: if (item in frequency): frequency[item] += 1 else: frequency[item] = 1 for key, value in frequency.items(): print("% s -> % d" % (key, value))OutputRunning the above code gives us the following result −a -> 2 b -> 1 c ... Read More
Kirchoff's theorem is useful in finding the number of spanning trees that can be formed from a connected graph.ExampleThe matrix 'A' be filled as, if there is an edge between two vertices, then it should be given as '1', else '0'.
You can use SELECT *FROM yourTableName in stored procedure. Let us first create a table −mysql> create table DemoTable654 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFirstName varchar(100) ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable654(StudentFirstName) values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable654(StudentFirstName) values('Sam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable654(StudentFirstName) values('Mike'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable654(StudentFirstName) values('Robert'); Query OK, 1 row affected (0.12 sec)Display all records from the table using ... Read More
IsomorphismIf two graphs G and H contain the same number of vertices connected in the same way, they are called isomorphic graphs (denoted by G ≅ H).It is easier to check non-isomorphism than isomorphism. If any of these following conditions occurs, then two graphs are non-isomorphic −The number of connected components are differentVertex-set cardinalities are differentEdge-set cardinalities are differentDegree sequences are differentExampleThe following graphs are isomorphic −HomomorphismA homomorphism from a graph G to a graph H is a mapping (May not be a bijective mapping) h: G → H such that − (x, y) ∈ E(G) → (h(x), h(y)) ∈ ... Read More
This function return the string representing a character whose Unicode code point is the integer supplied as parameter to this function. For example, chr(65) returns the string 'A', while chr(126) returns the string '~'.SyntaxThe syntax of the function is as below.chr(n) where n is an integer valueExampleThe below program shows how the chr() is used. We supply various integer values as parameter and get back the respective characters. Live Demo# Printing the strings from chr() function print(chr(84), chr(85), chr(84), chr(79), chr(82))Running the above code gives us the following result −T U T O RUsing a series of numbersWe can take help ... Read More
To change order of items in MySQL, use ORDER BY alias name. Let us first create a table −mysql> create table DemoTable653 (Product1Amount int, Product2Amount int); Query OK, 0 rows affected (0.42 sec)Insert some records in the table using insert command −mysql> insert into DemoTable653 values(400, 250); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable653 values(500, 300); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable653 values(40, 400); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable653 values(200, 450); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable653 values(50, 20); Query ... Read More
Let us first create a table −mysql> create table DemoTable651 (Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value varchar(100)); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable651(Value) values('Title'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable651(Value) values('course'); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable651(Value) values('subject'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement −mysql> select *from DemoTable651;This will produce the following output −+----+---------+ | Id | Value | +----+---------+ | 1 | ... Read More
A graph can exist in different forms having the same number of vertices, edges, and also the same edge connectivity. Such graphs are called isomorphic graphs. Note that we label the graphs in this chapter mainly for the purpose of referring to them and recognizing them from one another.Isomorphic GraphsTwo graphs G1 and G2 are said to be isomorphic if −Their number of components (vertices and edges) are same.Their edge connectivity is retained.Note − In short, out of the two isomorphic graphs, one is a tweaked version of the other. An unlabelled graph also can be thought of as an ... Read More
Many times we may need to convert the data types of one or more columns in a pandas data frame to accommodate certain needs of calculations. There are some in-built functions or methods available in pandas which can achieve this.Using astype()The astype() method we can impose a new data type to an existing column or all columns of a pandas data frame. In the below example we convert all the existing columns to string data type.Example Live Demoimport pandas as pd #Sample dataframe df = pd.DataFrame({ 'DayNo': [1, 2, 3, 4, 5, 6, 7], 'Name': ['Sun', 'Mon', 'Tue', 'Wed', ... Read More
For this, use aggregate function COUNT(). Let us first create a table −mysql> create table DemoTable650 (Value1 int, Value2 int); Query OK, 0 rows affected (0.83 sec)Insert some records in the table using insert command −mysql> insert into DemoTable650 values(100, 500); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable650 values(100, 500); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable650 values(100, 500); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable650 values(100, 500); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable650 values(200, 500); Query OK, 1 row affected (0.12 sec)Display ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP