Make your life easier with these itertools when dealing with iterables
“A lie gets halfway around the world before the truth has a chance to get its pants on.” ― Anonymous
Python provides the itertools package which provides convenience functions for many common iterator operations. We have covered count(), cycle() and chain() in the first part of this series, and compress(), dropwhile(), and groupby() in the second part. In this article, we present a few examples of ifilter(), islice(), imap() and izip().
Continue reading “Python itertools – ifilter, islice, imap, izip”
Remove items from a List and more.
“Happiness is a perfume you cannot pour on others without getting some on yourself.” ― Ralph Waldo Emerson
In a previous article, we covered some python list methods related to adding items. Let us now continue the review of more list methods.
Continue reading “Python – More List Methods and Recipes”
Check out this refresher on ways to add items to python lists
“Share your knowledge. It is a way to achieve immortality.” ― Dalai Lama XIV
Continue reading “Python List Methods: Adding Items”
Convert one value to another in a Streams Operation
“Always and never are two words you should always remember never to use. ” ― Wendell Johnson
Do you know about Java 8 Streams?
Java 8 streams is a very powerful facility for working with collections. What formerly required multiple lines of code and loops can now be accomplished with a single line of code. A part of Java 8 streams is the map() facility which can map one value to another in a stream. In this article, let us examine some common use cases where map() is useful.
Continue reading “Java 8 Streams Map Examples”
Learn about several methods to remove items in a loop from a java collection.
“Puns are the highest form of literature.”
― Alfred Hitchcock
When you have a List or a Set or any other Collection, you may sometimes need to remove items in a loop. For example, you may be maintaining a list of messages for processing, and need to occasionally purge stale items from the list. In such a scenario, you would loop around the collection and remove the stale items.
Continue reading “Removing Items in a Loop from a List”
A ListIterator allows traversal of a Java ArrayList in forward or backward direction.
“A man devoid of hope and conscious of being so has ceased to belong to the future.”
― Albert Camus, The Myth of Sisyphus and Other Essays
Java’s ArrayList class provides a list iterator which allows, among other things, traversal of the list in either direction. This is in comparison to a normal Iterator that allows traversal of the list in forward direction only. In this article, we delve into the usage and behavior of the ListIterator when used with an ArrayList.
Continue reading “Using Java ArrayList’s List Iterator”
Easily search a java list using java 8 predicate functions.
“Make improvements, not excuses. Seek respect, not attention.”
― Roy T. Bennett, The Light in the Heart
Searching, sorting and iterating are some of the fundamental operations required when using a list. Searching refers to finding one or more objects in the list that match a given condition. In this article, we look at some methods for searching a list in java.
Continue reading “Searching a List in Java”
Learn about ArrayList and LinkedList performance. In this article, we test creation, addition and iteration performance of these containers.
“Don’t mistake activity with achievement.”
― John Wooden
Let us examine the performance characteristics of List Implementations – ArrayList and LinkedList. We perform the testing for a variety of list sizes from 100 items to 1M items. We use the JMH test harness to conduct the test on a single core machine. Results are presented below.
Continue reading “Java ArrayList Benchmark”