Posts

Python Dictionary: How to Make Subset Easily

Image
Here's an easy method to make a subset of a  Dictionary in Python. You already know that Dictionary has a format of Key, Value and enclosed in curling bracket. Below are ideas with sample logic and how it works. It is useful for your projects and interviews too. Here is a Dictionary my_first_dict = { 'HP' : 100 'IBM': 200 'NTT' : 300 'ABC' : 400 'GDF' : 500 } I want to make a subset. The values are greater than 100 and less than 400. How can you achieve this? Don't worry you can do this easily. I am sharing logic with you. Here is subset Logic: You Can do it Using Dictionary Comprehension Syntax: sub_set = { key:value for key, value in my_first_dict.items() value >100 and value <400} Result References Python Programming: Using Problem Solving Approach

Python Class: Here is Useful Reason to Pass Self

Image
Here is the top reason to pass the 'self' argument in the Python class function. You already know that the python class has two things. One is function and the other one is members.  Structure of a Class class <name of the class>:  def <function name>(<arguments>):  ...  <members> For example, the employee class having data members name and age and member functions getdata() and putdata() can be defined as below. Every function in the class must have at least one argument, self . The data members are accessed via the self object as they belong to the class and not just the function. Likewise, the putdata() function displays the values of the data members. Notes on Python Class A class definition has functions but can also have other members. The attribute of an object is a data attribute, and the function that belongs to an object is the method. Sample Python Class class employee:  def getdata(self):  self.name=input('Enter name\t:')  self.age=in

Python Abstract Classes to Learn Quickly

Image
Here's the best example of how to understand the abstract classes of python quickly. An abstract class means it is a skeleton. You cannot instantiate abstract classes. For Example: The abstract class name is 'dog' o = dog() It gives an error. Since the ' dog' is an abstract class. I am sharing with you a clear understanding of abstract class. So that you can tell confidently about these classes. The syntax for Abstract Class from abc , import ABC , abstractmethod  class <class name>(ABC): @abstractmethod  def <method name>():  #abstract class definition Python Abstract Class Explanation from abc import ABC, abstractmethod class AbsBaseClass(ABC): def __init__(self): print("Abstract class") @abstractmethod def abMeth(self): pass def conMeth(self): print("I'm a concrete method") class Derived(AbsBaseClass): def abMeth(self): print("I'm redefined") o=Derived() o.abMeth() o.conMeth() References Star Python Certification

10 Kafka Interview Questions That Recently Asked

Image
Here're ten interview questions that were asked during Kafka's interview.  These are useful to update your knowledge. Kafka Interview Questions 1. What is Kafka? Kafka is a framework of Publisher and Subscribe. It reads messages from the Producer and allows them to read by Subscribers. It keeps store all the producer messages in the form of topics (underlying partitions). It also maintains logs. 2. What is a Consumer group? Each consumer is part of some Consumer group. By adding more consumers to a Consumer group, you can balance the load. In general, the Consumer group reads data from the same topic. The number of partitions in a Topic always should be the same as Consumers in a particular CG (consumer group). 3. What is Fault-Tolerance? Each partition is replicated on multiple servers. So, when one partition is failed, the other backup will deliver. So this concept is called Fault-tolerance. 4. Can we decrease the partitions that we created? No, you can't decrease the par

10 Top Tech Mahindra Fresher Interviews Questions

Image
Here're the ten top interview questions asked during fresher interviews. These are general questions and applicable for all B.Tech branches. 10 Interview Questions 1. What is Full-Service Web-hosting? It is a service offered by website hosting companies. So that the site can be accessed via the world wide web. 2. What is meant by Port blocking within LAN? It restricts the users to access services through various ports. The ports are USB, DVD port, Floppy, Removal device ports. 3. What is IDN? It enables people to use Domain names in local languages. 4. Can we call one program (not include) from another program? Yes, you can call. Here not include means external program. 5. How can you sort the elements of an array in descending order? In C++, you can use Array.Reverse(arr); 6. How do I update my DNS records? You can update DNS records in CNAME. Here're more options. 7. How do non-root -bridges decide, which port will affect the root port? In each non-root bridge (CAT2, CAT3, CA

Print Dictionary Values Simplified Logic

Image
Here's for loop logic that says how to use Dictionary to get its data. I will present here how to use it as input In for loop. You can also call Dictionary as Map, Hash, or Associative array. How to Print Dictionary Values Simplified With For loop Below is my example. I have created a simple Dictionary called 'store.' Then, I will get its data using for-loop. Here's my previous post Python -  How to Lookup Dictionary By Key . Dictonary Example Store = { "rao" : 1, "srini' : 2} For Loop Logic for key in store:       print (key, store[key]) Laptop batteries can last longer if you charge them up to only 80% instead of the full 100%. - By Lifehack.org Real-Time Result The execution of for loop showed here. It's much simple. Just use the code as I did. You'll get the desired result quickly. References Python for Everybody: Exploring Data in Python 3 SOFT SKILLS for a BIG IMPACT: Banish Self-Doubt, Improve Workplace Ethics

Python Constructors Init and Del Easy Way to Understand

Image
Python class has two constructors. One is the init, and the other one is del. Why you need these two and their real purpose explained. The initialization method is called __init__ while the finalization or destructor method is called __del__. Python methods with a double underscore character are for internal (not intended for direct access by the outside world) use. There are no true private methods in Python classes, but convention says that a method that begins with a single underscore is considered private, and a double underscore indicates it is internal (only to be used by the system.) Python Constructors Init and Del Easy Way to Understand Init Constructor object.__init__(self[, ...]) Called after the instance has been created (by __new__() ), but before it is returned to the caller. The arguments are those passed to the class constructor expression.  If a base class has an __init__() method, the derived class’s __init__() method, if any, must explicitly call it to ensure prope