Posts

How to Count Vowels in Input Quickly

Image
Here you'll know how python counts characters in the input. This is an interview question asked recently. How to Count Vowels in Input String Below is the Interview Question Vowels = ('aeiou') You need to check any vowels are present in the input string. Vowels means 'a', 'e', 'i', 'o', 'u'. The below function checks each character of input and compares it with the Vowels. 3 Steps to Count Vowels in Input You can achieve this in three steps. 1. Create a function called 'my_vowel' (the name up to you) 2. Use Set & Intersection Method 3. Run the function 1. Created 'my_vowel' Function #!usr/bin/python #This function finds vowel counts #welcome to my function """ Optional description """ def my_vowel (a): vowels = set ( 'aeiou' ) a_1 = vowels . intersection( set (a)) # initialized the dictionary found = { 'a' : 0 , 'e' : 0 , 'i' : 0 ,

Python - How to Lookup Dictionary by Key

Image
Here's Python Dictionary that explained how to lookup it using Key. Dictionary in Python is Key/Value pair. It's different from the list. The basic rule to identify; is enclosed in flower brackets ({}). Here's a demo about lookup and how to test it.  Dictionary = { 'key' : 'value', 'key: value'  }   IN THIS PAGE Python Dictionary Python Lookup How to check Lookup working or not Dictionary Example my_dict = {'name' : 'srini' , 'salary' : '100000', 'skills' : 'python' } Here, 'name' is the label. Then, : Then, 'srini' -> Value Explanation Data is enclosed in flower brackets It's an unordered list You can manipulate data (mutable) You can access the value of a particular key. So, in Python, it's called a Lookup. It's one of the best interview questions. You May Also Like :  Python Dictionary Vs List With Examples Lookup Dictionary by Key Python Lookup (a.k.a Dictionary). You

How to Use List Function in Python

Image
Here's is an answer to calculate the length of the repeated lists. LIST is a principle data type in Python that holds a list of values. Usually strings. List() Function the Real Usage You can do various operations with Lists. The best examples are REPEAT, APPEND, INSERT, EXTEND, COUNT. Still more you can do. Note: This question is from a test recently held by an HR company. HR firms usually ask to take an online test to filter the job-seekers. IN THIS PAGE 1. Question 2. How to Find Length Interview Question  The '* 2' says times the list is repeated. In this question, they have given '2' times. my_list = ['srini', 'seetha', 'rao'] b = len(list(list(list(list(list(my_list*2)))))) Print (b) Select Answer 1. 5 2. 6 3. 7 4. None Explanation: In the first step, the '*' says, you repeated the List two times. It confuses the test-taker since they have given multiple functions of the list(). How to get Length You can code the way I did. So

Python: How to find List Max & Min Easily

Image
Here's logic to find Max and Min values in a List. Without using built-in Max() and Min () functions you can find Max and Min values in a List. For that matter, you need to write a user-defined function. This post is all about how to write it and run. Python: Find Max and Min in a List You can achieve this by writing a user-defined function. Here's useful logic and steps to write it precisely. IN THIS PAGE Write a Function Execute Function Get the result Write Function You can write an user-defined function to get MAX and MIN values. In this function, I am using the max(), min() built-in functions. The other variables you can use as you wish. Below is the my actual logic. Sample Code def findmaxmin (data): ax = max (data) by = min (data) return (x,y) data = ( 109 , 98 , 88 , 7 ) (maximum, minimum) = findmaxmin (data) print ( "Maximum Marks = " , maximum) print ( "Minimum Marks = " , minimum) Created a Script Using vim editor Here as the first s

Python - How to Define CLASS in Script

Image
Here's an example of the Python define class in Script. Here you can create CLASS in Script and run and test it. You are aware that Python supports Classes as part of Object-Oriented Programming Capabilities. You can create an Object from the Class. Also, you can use the methods of that. Python class within the script Sample code Actual code in Script Run Script Python class within the script Sample Code - Below is the code that gives indentation errors. However, I have corrected the actual script. class Employee: """Base class""" empCount = 0 def __init__(self, name, salary): self.name = name self.salary = salary Employee.empCount += 1 # can also be written as Employee.empCount = Employee.empCount + 1 def displayEmployee(self): # function is defined here print "Name : ", self.name, ", Salary: ", self.salary # "emp1 is the first object of Employee class" emp1 = Employee("Akhil", 2000) # "emp2 is

How to Read Kafka Logs Quickly

Image
In Kafka, the log file's function is to store entries. Here, you can find entries for the producer's incoming messages. You can call these topics. And,  topics are divided into partitions. How to Read Logs in Kafka IN THIS PAGE Kafka Logs How Producer Messages Store Benefits of Kafka Logs How to check Logs in Kafka 1. Kafka Logs The mechanism underlying Kafka is the log . Most software engineers are familiar with this. It tracks what an application is doing.  If you have performance issues or errors in your application, the first place to check is the application logs. But it is a different sort of log.  In the context of Kafka (or any other distributed system), a log is "an append-only, totally ordered sequence of records - ordered by time. Kafka Basics [Video] 2. How Producer Messages Store The producer writes the messages to Broker, the records store in a log file. The records stored as 0,1,2,3 and so on. Each record will have one unique id. 4. Benefits of Kafka Logs L

How to Check Kafka Available Brokers

Image
Here's the command to check the list of brokers present in a Kafka Cluster. You can say the Broker is the heart of Kafka-cluster. In simple terms, it works as a process. The main function is to receive messages from publishers and gives permission to access messages by consumers. How to Check Available Brokers in Kafka Here is the command: linux$ ./zookeeper-shell.sh zookeeper-IPaddress:2181 | "ls /brokers/ids" Just use the above command to get the number of brokers present in your host (Kafka Cluster). What is Default Broker-id in Kafka  The default broker id is -1 . When you create a new broker, it adds to -1. Then, it gives a new broker id. The broker ids will be generated from  reserved.broker.max.id + 1. Types of broker ids. Use assigned Zookeeper generated broker id. According to Wiki: Kafka runs on a cluster of one or more servers (called brokers), and the partitions of all topics are distributed across the cluster nodes.  Additionally, partitions are replicated t