This is not a Python Starter Tutorial but advanced Python Tips in a Random Order. Do you know the use of ‘else’ in loop (for and while) in Python? The ‘else’ part of statements will get executed only if the for loop completes and reaches it’s end without any ‘break’. #1 Let’s take an example:Continue reading “Python Random Tips #9”
Tag Archives: Python
Random Machine Learning #2
What is Feature Scaling? During the data pre-processing stage, feature scaling is used to scale the independent variables within the same range (say between 0 and 1 or between -1 and +1). Why we need to do the feature scaling? This will ensure no independent variable dominates the machine learning algorithms. Do you know? FeatureContinue reading “Random Machine Learning #2”
Python Random Tips #7
This is not a Python Starter Tutorial but advanced Python Tips in a Random Order. In this section, let us see some quick questions & answers with Python code examples: #1 How to remove the last element from a Python list? #2 append() vs entend()? Append() adds the element to the end of the list.Continue reading “Python Random Tips #7”
Random Python Questions #4
0.1 + 0.4 == 0.5 The above is ‘True’, using Python script execution, right? Of course, yes. But if you try in Python script 0.1 + 0.2 == 0.3 this will return ‘False‘. It supposed to return ‘True’ but why it gives ‘False’. Why? Do you know some of the above == return ‘False’ insteadContinue reading “Random Python Questions #4”
Random Python Questions #1
What is the result of the below Python code: from collections import Counterinput_dictionary = {‘a’:5, ‘b’:3, ‘c’: 1, ‘b’:2}print(Counter(input_dictionary)) Result:Counter({‘a’: 5, ‘b’: 2, ‘c’: 1}) Question: Even-though we have 2 values for the key ‘b’ in “input_dictionary”, the result has only one ‘b’ key/value pair. Do you know why? What’s the reason?