Found 34494 Articles for Programming

Page Rank Algorithm and Implementation using Python

karthikeya Boyini
Updated on 26-Jun-2020 12:32:55

4K+ Views

The PageRank algorithm is applicable in web pages. Web page is a directed graph, we know that the two components of Directed graphsare -nodes and connections. The pages are nodes and hyperlinks are the connections, the connection between two nodes.We can find out the importance of each page by the PageRank and it is accurate. The value of the PageRank is the probability will be between 0 and 1.The PageRank value of individual node in a graph depends on the PageRank value of all the nodes which connect to it and those nodes are cyclically connected to the nodes whose ... Read More

Binary to decimal and vice-versa in Python

AmitDiwan
Updated on 11-Aug-2022 11:22:14

746 Views

In this article, we will see how to convert Binary to Decimal and Decimal to Binary. Binary is the simplest kind of number system that uses only two digits of 0 and 1 (i.e. value of base 2). Since digital electronics have only these two states (either 0 or 1), so binary number is most preferred in modern computer engineer, networking and communication specialists, and other professionals. Decimal number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system, the successive positions to the left of the decimal point represent units, tens, hundreds, ... Read More

Quine in Python

AmitDiwan
Updated on 12-Aug-2022 12:17:14

1K+ Views

The Quine is a program, which takes no input, but it produces output. It will show its own source code. Additionally, Quine has some conditions. We cannot open the source code file inside the program. Example 1 Here a simple string formatting is working. We are defining a variable ‘a’, and inside a, we are storing ‘a=%r;print (a%%a)’ Then we are printing the value of a, and also replacing %r with the value of a. Thus the quine is working − a='a=%r;print (a%%a)';print (a%a) Output a='a=%r;print (a%%a)';print (a%a) Example 2 We defined a variable _ and assigned ‘_=%r;print ... Read More

Handling missing keys in Python dictionaries

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

1K+ Views

In Python there is one container called the Dictionary. In the dictionaries, we can map keys to its value. Using dictionary the values can be accessed in constant time. But when the given keys are not present, it may occur some errors. In this section we will see how to handle these kind of errors. If we are trying to access missing keys, it may return errors like this. Example code Live Demo country_dict = {'India' : 'IN', 'Australia' : 'AU', 'Brazil' : 'BR'} print(country_dict['Australia']) print(country_dict['Canada']) # This will return error Output AU --------------------------------------------------------------------------- KeyErrorTraceback (most ... Read More

JSON Formatting in Python

Samual Sam
Updated on 26-Jun-2020 12:26:45

8K+ Views

The JSON (Java Script Object Notation) is light weight, well accepted data interchange format. Using JSON formatting techniques in Python, we can convert JSON strings to Python objects, and also convert Python Objects to JSON strings.To use these functionalities, we need to use the json module of Python. The json module comes with the Python standard library. So at first we have to import it first.import jsonConverting Python objects to JSON StringIn the json module, there are some methods like dump(), and dumps() to convert Python objects to JSON strings. The dump() method takes two arguments, the first one is ... Read More

Type Conversion in Python

Samual Sam
Updated on 30-Jul-2019 22:30:23

1K+ Views

Using Python, we can easily convert data into different types. There are different functions for Type Conversion. We can convert string type objects to numeric values, perform conversion between different container types etc. In this section we will see how the conversions can be done using Python. Converting String to Numeric Types To convert from String type objects to Numeric Objects, there are different methods like int(), float() etc. Using the int() method we can convert any number as string to integer value (base 10). It takes the string type argument, default base is 10, We can also specify the ... Read More

Operator Functions in Python

karthikeya Boyini
Updated on 30-Jul-2019 22:30:23

644 Views

In Python there are some additional standard library methods for mathematical operations, like arithmetic, logical, relational, bitwise etc. operations. These methods can be found under the operator module. To use it at first we need to import it the operator standard library module. import operator In this section we will see some operator functions for bitwise operations and container operations. Arithmetic Operations At first we will see the arithmetic operating functions. These are like below. Sr.No Functions & Description 1 add(x, y) The add() method is used to add two numbers x and y. ... Read More

Merge two sorted arrays in Python using heapq?

Samual Sam
Updated on 26-Jun-2020 12:19:06

416 Views

In this section we will see how two sorted lists can be merged using the heapq module in Python. As an example, if list1 = [10, 20, 30, 40] and list2 = [100, 200, 300, 400, 500], then after merging it will return list3 = [10, 20, 30, 40, 100, 200, 300, 400, 500]To perform this task, we will use the heapq module. This module comes with Python as Standard Library Module. So we need to import it before using it.import heapqThe heapq module has some properties. These are like below −Method heapq.heapify(iterable)It is used to convert an iterable dataset ... Read More

Creating child process using fork() in Python

karthikeya Boyini
Updated on 26-Jun-2020 12:19:41

2K+ Views

Our task is to create a child process and display process id of both parent and child process using fork() function in Python.When we use fork(), it creates a copy of itself, it is a very important aspect of LINUX, UNIX. fork() is mainly applicable for multithreading environment that means the execution of the thread is duplicated created a child thread from a parent thread. When there is an error, the method will return a negative value and for the child process, it returns 0, Otherwise, it returns positive value that means we are in the parent process.The fork() module ... Read More

Determine if a String is a legal Java Identifier

karthikeya Boyini
Updated on 26-Jun-2020 12:20:41

691 Views

To determine if a String is a legal Java Identifier, use the Character.isJavaIdentifierPart() and Character.isJavaIdentifierStart() methods.Character.isJavaIdentifierPart()The java.lang.Character.isJavaIdentifierPart() determines if the character (Unicode code point) may be part of a Java identifier as other than the first character.A character may be part of a Java identifier if any of the following are true.it is a letterit is a currency symbol (such as '$')it is a connecting punctuation character (such as '_')it is a digitit is a numeric letter (such as a Roman numeral character)Character.isJavaIdentifierStart()The java.lang.Character.isJavaIdentifierStart() determines if the character (Unicode code point) is permissible as the first character in a Java ... Read More

Advertisements