Using recursive function instead of large list