Counting Frequencies in a List Using Dictionary in Python

Pradeep Elance
Updated on 23-Aug-2019 11:53:22

3K+ Views

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

Kirchhoff's Theorem

Mahesh Parahar
Updated on 23-Aug-2019 11:50:24

3K+ Views

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'.

MySQL Stored Procedure Won't Fetch the Whole Table

AmitDiwan
Updated on 23-Aug-2019 11:46:35

196 Views

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

Isomorphism and Homeomorphism of Graphs

Mahesh Parahar
Updated on 23-Aug-2019 11:44:45

9K+ Views

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

chr() Function in Python

Pradeep Elance
Updated on 23-Aug-2019 11:42:08

1K+ Views

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

Change Order of Items in MySQL

AmitDiwan
Updated on 23-Aug-2019 11:39:37

505 Views

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

Search Record with Specific Value in MySQL using LIKE or REGEXP

AmitDiwan
Updated on 23-Aug-2019 11:33:17

484 Views

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

Isomorphism in Mathematics and Computer Science

Mahesh Parahar
Updated on 23-Aug-2019 11:31:41

907 Views

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

Change Data Type for One or More Columns in Pandas DataFrame

Pradeep Elance
Updated on 23-Aug-2019 11:30:14

2K+ Views

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

Count Occurrences of Integer in MySQL Column

AmitDiwan
Updated on 23-Aug-2019 11:27:21

318 Views

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

Advertisements