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 6321127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:05:45+00:00 2026-05-24T16:05:45+00:00

Sorry for the title, my problem is as follows. I have a list of

  • 0

Sorry for the title, my problem is as follows. I have a list of paths and I want to get multiple common prefixes. For example, given I have:

['/usr/local/lib/python2.7/dist-packages/pkg_name-0.1-py2.7.egg/pkg_name',
 '/usr/local/lib/python2.7/dist-packages/pkg_name-0.1-py2.7.egg/EGG-INFO',
 '/usr/bin/pkg_name']

I want to have:

['/usr/local/lib/python2.7/dist-packages/pkg_name-0.1-py2.7.egg/',
 '/usr/bin/pkg_name']

Because the first two have a common prefix that is a directory. Hope I made this clear,

rubik

EDIT: The paths I have are Python eggs and some executables. I want to remove the entire egg, not the directories inside it, like EGG-INFO or pkg_name. So it has to be /usr/.../dist-packages/pkg_name-0.1-py2.7.egg/. The other path, since it is an executable remains as it is.

Thank you

  • 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-05-24T16:05:45+00:00Added an answer on May 24, 2026 at 4:05 pm

    The problem is not well-defined. What do you want to have in this case:

    /usr/bin/a
    /usr/bin/b
    /usr/etc
    /usr/local
    

    Shall it be one /usr or two: /usr/bin /usr, or three?

    In either case, the algorithm will be like this:

    1. sort the list
    2. take the first element and do os.path.commonprefix() with 2nd, 3rd, …, i-th until common prefix is not /; that will be your first group
    3. repeat step 2, starting from (i+1)th
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

sorry for the title.. my problem is on how to get a specific part
Sorry for title, I have an interop problem. The C dll that I'm using
I'm sorry if this title doesn't describe the problem properly but I wasn't sure
Sorry for the vague title, as I really can't explain this problem succinctly. Basically
sorry for the bad title, I don't know how to describe my problem. I
Sorry for a long question and not a very descriptive title, but my problem
Not sure the title fully describes the problem/question I'm trying to ask, sorry. One
Sorry the title may not be very clear. Basically I have a wrapper for
Sorry the title's so convoluted... I must've tried for ten minutes to get a
Sorry if the title doesn't make sense. Basically I have a series of strings

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.