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?

Python Random Tips #5

This is not a Python Starter Tutorial but advanced Python Tips in a Random Order. What is Python Counter? Python Counter is a container that keeps a count of the number of occurrences of any value in the container. Python Counter helps to count the key-value pairs in an object. With the inputs such asContinue reading “Python Random Tips #5”

Python Random Tips #4

This is not a Python Starter Tutorial but advanced Python Tips in a Random Order. What are the differences between sorted() and sort() : #1 The output of the sorted() built-in function is a new list and no changes to the original input. As you can see the original ‘colors’ list is unchanged after theContinue reading “Python Random Tips #4”

Design a site like this with WordPress.com
Get started