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
Server Side Programming Articles - Page 1386 of 2650
1K+ Views
Given a nested list we want to convert it to a dictionary whose elements can be considered as part of a tree data structure. In this article we will see the two approaches to convert a nested list into to add dictionary whose elements represent a tree like data structure.Using SlicingWe reverse the items in the list aby slicing and then check if the item is present in the list. If it is not present we ignore it else we add it to the tree.Exampledef CreateTree(lst): new_tree = {} for list_item in lst: currTree = ... Read More
721 Views
Python dictionaries have keys and values. If we have two or more dictionaries to be merged a nested dictionary, then we can take the below approaches. Here year the dictionaries are given along with the new keys that will become a key in the nested dictionary.Assigning keysIn this approach we will create a new empty dictionary. Then assigned the given dictionaries to each new key. The resulting dictionary will be a nested dictionary with the keys assigned.ExampledictA = {'Sun': 1, 'Mon': 2} dictB = {'Tue': 3, 'Sun': 5} # Given Dictionaries print("DictA : ", dictA) print("DictB: ", dictB) ... Read More
2K+ Views
When analyzing data with python we come across situations when we have to merge two dictionaries in such a way that we add the values of those elements whose keys have equal values. In this article we will see such two dictionaries getting added.With For loop and | OperatorIn this approach we design a for loop to check for the presence of the value of the key in both the dictionaries and then add them. Finally we merge the two dictionaries using the | operator available for the dictionaries.ExampledictA = {'Mon': 23, 'Tue': 11, 'Sun': 6} dictB = {'Wed': 10, ... Read More
343 Views
Many times during data analysis using lists we come across a situation where we need to find out if a given element is present at least N Times in the given list. For example if 5 is present at least three times in the list or not. In this article we will see 2 approaches on how to achieve this.Counting OccurrencesIn the below approach we take the number and it's occurrences as an input. Then we e designer follow to keep the count of the occurrences. If the count value is greater than or equal to the required value then ... Read More
397 Views
The Pygorithm module is an educational module containing the implementation of various algorithms. The best use of this module is to get the code of an algorithm implemented using python. But it can also be used for actual programming where we can apply the various algorithms to a given data set.Finding the Data StructuresAfter installing the module in the python environment we can find the various data structures that is present in the package.Examplefrom pygorithm import data_structures help(data_structuresRunning the above code gives us the following result −OutputHelp on package pygorithm.data_structures in pygorithm: NAME pygorithm.data_structures - Collection of data structure ... Read More
10K+ Views
The os.path module is a very extensively used module that is handy when processing files from different places in the system. It is used for different purposes such as for merging, normalizing and retrieving path names in python . All of these functions accept either only bytes or only string objects as their parameters. Its results are specific to the OS on which it is being run.os.path.basenameThis function gives us the last part of the path which may be a folder or a file name. Please the difference in how the path is mentioned in Windows and Linux in terms ... Read More
2K+ Views
Python can connect to oracle using a python package called cx_Oracle. Oracle is one of the famous and widely used database and python’s data processing features are leverages well using this connectivity. In this article we will see how we can connect to oracle database and query the DB.Installing cx_OracleWe can use the below command to install the python package which can be used for establishing the connectivity.Examplepip install cx_OracleConnecting to OracleNow using this module we can connect to a oracle database which is accessible through the oracle service name. We create a cursor and execute the SQl query through ... Read More
1K+ Views
The netrc class in python is used to read the data from the .netrc file presnt in unix systems in user’s home firectory. These are hidden files containing user’s login credential details. This is helpful for tool slike ftp, curl etc to successfully read the ,netrc file and use it for their actions.The below program shows how we can read the .netrc file using python’s netrc module.Exampleimport netrc netrc = netrc.netrc() remoteHostName = "hostname" authTokens = netrc.authenticators(remoteHostName) # Print the access tokens print("Remote Host Name:%s" % (remoteHostName)) print("User Name at remote host:%s" % (authTokens[0])) print("Account Password:%s" % (authTokens[1])) print("Password for ... Read More
2K+ Views
In Python we work with variables, functions, libraries and modules, etc. Sometimes, the variable name you choose may already exist as the name of another variable, function, or method. This can be confusing or it might lead to unexpected behavior in your program. In such scenario, we need to learn about how all these names are managed in Python. This is the concept of namespaces and scoping. Namespaces in Python A namespace is a mapping from names to objects, which means stores the names you define in your program (such as, variable names, function names, class names, etc.) and maps ... Read More
619 Views
Encoders and decoders for the External Data Representation (XDR). When we transport data between different external sources, this is the commonly used format that is used. It useful for creation and transfer of complex data structures. XDR provides a service associated with the OSI Presentation Layer.In the below program we see how the data is getting packed and unpacked using the xdrlib module.Exampleimport xdrlib p = xdrlib.Packer() print(type(p)) lst = [1, 2, 3] p.pack_list(lst, p.pack_int) print(p) u = xdrlib.Unpacker(p) print(type(u)) print(lst)Running the above code gives us the following result −Output [1, 2, 3]Read More