Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8477579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:30:25+00:00 2026-06-10T18:30:25+00:00

I want to get a list but the last and the first elements. What

  • 0

I want to get a list but the last and the first elements. What is the most efficient way?

middle = init . tail

or:

middle = tail . init

And in the case of drop the n-first elements and the n-last elements?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:30:27+00:00Added an answer on June 10, 2026 at 6:30 pm

    It doesn’t matter (much) either way. Note that tail is O(1) whereas init is O(n). If you take the tail first then init has to examine (n-1) constructors, for a total of n constructors examined.

    If you take the init first then init examines n constructors and tail examines 1, for a total of n+1 constructors examined.

    So it’s every so slightly more efficient to do init . tail, but not so much more efficient that you should worry about it.

    The same applies to dropping the first k elements from the front and end of the list, except that it might make more of a difference. If you drop the initial elements first, then they don’t have to be examined when dropping the final elements, and you save a bit of time, so you should do

    dropLast k . drop k
    

    which examines n constructors, rather than

    drop k . dropLast k
    

    which examines n+k constructors.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the list of my database's elements. but i wonder, is
I have a List of ADUsers but foreach ADUSER I want to get its
I want to get the positions and lengths of the elements in a list.
I have an unsorted list but I want to sort in a custom way
I first want to get a list of files stored in an FTP directory
I want to get list of tables in a given database and a given
I want to get list of columns of a table using GetSchema method in
I want to get list of Domino Servers on the network, and accordingly login
i want to get list of all application or Threads attached with a process.For
I want to get list of methods in current file, when my tool is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.