Posts

No Fluff Guide to Python - P8 - Advanced Functions

Image
  You must fly before you can learn to walk!   #Zip Unzip parse two lists together for item in zip([ 10 , 20 , 30 ], [ 'x' , 'y' , 'z' ]):     print( item ) ( 10 , 'x ') ( 20 , 'y ') ( 30 , 'z ') The zip() function is used to combine multiple iterables (such as lists, tuples, or strings) into a single iterable object. It pairs corresponding elements from each input iterable and returns an iterator of tuples containing those pairs.     On the other hand, to "unzip" or separate the elements of a zipped iterable, you can use the zip() function in combination with the * operator. This is commonly known as "unzipping" the iterable. Here's an example: pairs = [(1, 'a'), (2, 'b'), (3, 'c')] numbers, letters = zip(*pairs) print(numbers) print(letters) Output: (1, 2, 3) ('a', 'b', 'c') Evaluate Expression given in String certain computations in string format and we ...

No Fluff Guide to Python - P7 - Dictionary

Image
  Dictionary Imagine you have a phone book.  You can look up a person's name  find their phone number.  You can also add new people to the phone book  remove people from the phone book. A Python dictionary is like a phone book.  You can store any kind of data in a dictionary like names, phone numbers, and addresses.  You can also access the data in a dictionary using a key. To create a dictionary, you use the {} curly braces.  Structured in a Key Value pair "Key": "Value" Create a dictionary, name and age dict = { "name" : "vish" , "age" : 30 }  Key: Value  Keys = IDs  animals = { "cat" : "meow" , "dog" : "woof" , "duck" : "quack" , "chicken" : "cluck"      "chicken" : "click" ❌ } #Dictionary keys do not allow duplicates   You can access any particular value: print (animals[ 'duck' ]) Output: quack   ...