Aug-01-2019, 09:13 PM
Hello friends, i have this code which counts number of apple in the fruit list, it returns 6 which is correct.
How can i tell python to count a fruit only if the next fruit is similar to the previous fruit and ignore others
where the previous fruit ain't similar.
So that in this case i get the count as 3 (i.e the 3 apple between lemon and banana in the list)
How can i tell python to count a fruit only if the next fruit is similar to the previous fruit and ignore others
where the previous fruit ain't similar.
So that in this case i get the count as 3 (i.e the 3 apple between lemon and banana in the list)
fruits=['mango','orange','apple','lemon','apple','apple','apple','banana','avocado','apple','mango','pineapple','orange','apple'] print(fruits.count('apple'))