
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 33676 Articles for Programming

326 Views
In this problem, we are given an array arr[] of size 2n. Our task is to create a program to find the sum over subset using dynamic programming to solve it.We need to calculate function, F(x) = Σ Ai such that x&i == i for all x. i.e. i is a bitwise subset of x.Let’s take an example to understand the problem, Input: A[] = {5, 7, 1, 9} , n = 2Output: 5 12 6 22Explanation: For n = 2 , there are 4 values of x. They are 0, 1, 2, 3.Now, calculating values of the function:F(0) = A0 ... Read More

2K+ Views
In this problem, we are given an array arr[] of size n. Our task is to create a program to find the sum of XOR of sum of all pairs in an array.Let’s see an example to understand the problem, Input: arr[5, 7, 9]Output: 22Explanation: (5+5) ^ (5+7) ^ (5+9) ^ (7+5) ^ (7+7) ^ (7+9) ^ (9+5) ^ (9+7) ^ (9+9) = 22A simple solution to the problem is by using a nested loop. And creating all possible pairs from the array. And calculate the XOR of the sum of each pair.Algorithm: Initialise XorSum = 0Step 1: iterate from 0 to n. Follow:Step 1.1: iterate ... Read More

4K+ Views
We can create our own cross-platform, language-independent server using the XML-RPC protocol.We use the SimpleXMLRPCServer to create the SimpleXMLRPCServer instance and tell it to listen for incoming requests. Next we define some functions to be part of the service and register those functions so that the server knows how to call it.Running the ServerIn the below example we create a server using the SimpleXMLRPCServer instance and register some pre-defined as well as custom functions. Finally, we put the server into an infinite loop receiving and responding to requests.Examplefrom xmlrpc.server import SimpleXMLRPCServer from xmlrpc.server import SimpleXMLRPCRequestHandler class RequestHandler(SimpleXMLRPCRequestHandler): rpc_paths = ... Read More

1K+ Views
XML stands for "Extensible Markup Language". It is mainly used in webpages, where the data has a specific structure. It has elements, defined by a beginning and an ending tag. A tag is a markup construct that begins with < and ends with >. The characters between the start-tag and end-tag, are the element's content. Elements can contain other elements, which are called "child elements".ExampleBelow is the example of an XML file we are going to use in this tutorial. Vicky, Matthew Geo-Spatial Data Analysis Python ... Read More

3K+ Views
Python does not have a null object. But the most closely related similar object is none. In this article, we will see how how None behaves in Python.Checking the type of Null and None we see that there is no Null Type and the None object is of type NoneType.Exampleprint(type(None)) print(type(Null))OutputRunning the above code gives us the following result −Traceback (most recent call last): File "C:\Users\xxx\scratch.py", line 4, in print(type(Null)) NameError: name 'Null' is not definedKey facts about NoneNone is the same as False.None is the same as False.None is the same as False.None is an ... Read More

8K+ Views
Everything in Python is an object including classes. All classes are instances of a class called "type".The type object is also an instance of type class. You can inspect the inheritance hierarchy of class by examining the __bases__ attribute of a class object. type() method returns class type of the argument(object) passed as parameter.If single argument type(obj) is passed to type method, it returns the type of given object. If three arguments type(name, bases, dict) is passed, it returns a new type object.Using type()Let’s look at the classes for the most used data types. In the below program we initialize ... Read More

2K+ Views
Code objects are a low-level detail of the CPython implementation. Each one represents a chunk of executable code that hasn’t yet been bound into a function. Though code objects represent some piece of executable code, they are not, by themselves, directly callable. To execute a code object, you must use the exec keyword.In the below example we see how the code objects are created for a given piece of code and what are the various attributes associated with hat code object.Example Live Democode_str = """ print("Hello Code Objects") """ # Create the code object code_obj = compile(code_str, '', 'exec') # get ... Read More

152 Views
If two variables are of the same data types and not iterators like list and dictionary etc, then the expressions a += b is same as a =+b gives the same result. But when n iterator is involved we can not always expect the same. Below is one of such scenario.Case of a = a +bHere we can see when we apply the expression to a list and a string expecting they will get merged, we get back an error.Examplex ='Hello ' z_list = [1, 2, 3] z_list = z_list + x print(z_list)OutputRunning the above code gives us the following ... Read More

475 Views
As we write python programs we need various other modules to leverage their functions, classes etc. in our current program. We can import those modules at the runtime using the import function. Though you can also import named modules at the beginning of the code, you may need the module temporarily for only few lines of code or you want to make the copy of an object from the module and modify and use it.SyntaxThe syntax of the __import__() function is −__import__(name, globals=None, locals=None, fromlist=(), level=0) Where name - the name of the module you want to import globals and ... Read More

380 Views
Pygame is a multimedia library for Python for making games and multimedia applications. In this article we will see how to use the pygame module to draws many different shapes on the screen taking into consideration, its height, width and position in the pygame window.In the below program we initialize the pygame moduel and then deifne the colour and dimension for the image. Next we add the different shapes as per the syntax and carefully mention the arguments to the darw functions so that the images do not overlap with each other. The screen.blit function paints the screen while the ... Read More