The Zip Function
In Python, we have an assortment of built-in functions that allow us to build our programs faster and cleaner. One of those functions is zip() . The zip() function allows us to quickly combine associated data-sets without needing to rely on multi-dimensional lists. While zip() can work with many different scenarios, we are going to explore only a single one in this article. Let’s use a list of student names and associated heights as our example data set: Jenny is 61 inches tall Alexus is 70 inches tall Sam is 67 inches tall Grace is 64 inches tall Suppose that we already had a list of names and a list of heights: names = [ "Jenny" , "Alexus" , "Sam" , "Grace" ] heights = [ 61 , 70 , 67 , 64 ] If we wanted to create a nested list that paired each name with a height, we could use the built-in function zip() . The zip() function takes two (or more) lists as inputs and returns an object that contains a list of p...
Comments
Post a Comment