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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:09:25+00:00 2026-06-18T20:09:25+00:00

myList = [ 4,’a’, ‘b’, ‘c’, 1 ‘d’, 3] how to split this list

  • 0
myList = [ 4,'a', 'b', 'c', 1 'd', 3]

how to split this list into two list that one contains strings and other contains integers in elegant/pythonic way?

output:

myStrList = [ 'a', 'b', 'c', 'd' ]

myIntList = [ 4, 1, 3 ]

NOTE: didn’t implemented such a list, just thought about how to find an elegant answer (is there any?) to such a problem.

  • 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-18T20:09:26+00:00Added an answer on June 18, 2026 at 8:09 pm

    As others have mentioned in the comments, you should really start thinking about how you can get rid of the list which holds in-homogeneous data in the first place. However, if that really can’t be done, I’d use a defaultdict:

    from collections import defaultdict
    d = defaultdict(list)
    for x in myList:
       d[type(x)].append(x)
    
    print d[int]
    print d[str]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one customized list MyList that extends ArrayList, like this: class MyList extends
I have this list: mylist = [20, 30, 25, 20, 30] After getting the
if not any(myList[0:5]): does this also work with a dictionary instead of a list?
I created a class MyList that has a field private LinkedList<User> list; I would
I have a custom List MyList that is an extension of List , and
Example: public class MyList<T> : List<T> { public MyList(List<T> list) { this = list;
I have this list: myList<-list(c(Developmental Biology, Neuroscience, Cell Biology ), c(Developmental Biology, Neuroscience, Cell
In this example: abstract class MyList<T>: List<T> { public T Find(int? id) { foreach(T
I want to do this: MethodInfo m = myList.GetType().GetMethod(ConvertAll, System.Reflection.BindingFlags.InvokeMethod).MakeGenericMethod(typeof(object)); List<object> myConvertedList = (List<object>)m.Invoke(myList,
In Python 2.6.5, given this list mylist = [20, 30, 25, 20] Why does

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.