• Q & A – Python List

    Q & A – Python List

    (1) Check If A List Contains An Element. The in operator will return True if a specific element is in a list. lst = [‘Subrat’,’Arpita’,’Abhispa’,’Subhada’] ‘Subhada’ in lst True (2) How To Iterate Over 2+ Lists At The Same Time. You can zip() lists and then iterate over the zip object. A zip object is an iterator of tuples. Below we iterate over 3 lists simultaneously and interpolate the values into a string. name = [‘Snowball’, ‘Chewy’, ‘Bubbles’, ‘Gruff’] animal = [‘Cat’, ‘Dog’, ‘Fish’, ‘Goat’] age = [1, 2, 2, 6] z = zip(name, animal, age) for i, j, k in z: print(f"Name: {i} Animal: {j} Age: {k}")

    Read More