how to detect logical and string index in sub-list and delete it












1














I have a list like this:



A = [[1,2,3,4],[1,1,2,4],[1,2,3,False],[1,False,2,3],[1,2,3,4],[1,2,3,'word'],[5,6,7,8],[1,4,3,4],[True,1,2,4],[0,1,0,1],[0,0,0,0],[False,False,False,False]]


and I want as output a list like this:



A = [[1,2,3,4],[1,1,2,4],[1,2,3,4],[5,6,7,8],[1,4,3,4],[0,1,0,1],[0,0,0,0]]


I just want to delete or remove a any list. it have member of string or logical.
how i can do it.










share|improve this question
























  • So you want to remove any lists that have False in them?
    – Ayxan
    Nov 10 at 18:16










  • yeap, I want to remove any type is not int or float from list.
    – lyca
    Nov 10 at 18:18


















1














I have a list like this:



A = [[1,2,3,4],[1,1,2,4],[1,2,3,False],[1,False,2,3],[1,2,3,4],[1,2,3,'word'],[5,6,7,8],[1,4,3,4],[True,1,2,4],[0,1,0,1],[0,0,0,0],[False,False,False,False]]


and I want as output a list like this:



A = [[1,2,3,4],[1,1,2,4],[1,2,3,4],[5,6,7,8],[1,4,3,4],[0,1,0,1],[0,0,0,0]]


I just want to delete or remove a any list. it have member of string or logical.
how i can do it.










share|improve this question
























  • So you want to remove any lists that have False in them?
    – Ayxan
    Nov 10 at 18:16










  • yeap, I want to remove any type is not int or float from list.
    – lyca
    Nov 10 at 18:18
















1












1








1







I have a list like this:



A = [[1,2,3,4],[1,1,2,4],[1,2,3,False],[1,False,2,3],[1,2,3,4],[1,2,3,'word'],[5,6,7,8],[1,4,3,4],[True,1,2,4],[0,1,0,1],[0,0,0,0],[False,False,False,False]]


and I want as output a list like this:



A = [[1,2,3,4],[1,1,2,4],[1,2,3,4],[5,6,7,8],[1,4,3,4],[0,1,0,1],[0,0,0,0]]


I just want to delete or remove a any list. it have member of string or logical.
how i can do it.










share|improve this question















I have a list like this:



A = [[1,2,3,4],[1,1,2,4],[1,2,3,False],[1,False,2,3],[1,2,3,4],[1,2,3,'word'],[5,6,7,8],[1,4,3,4],[True,1,2,4],[0,1,0,1],[0,0,0,0],[False,False,False,False]]


and I want as output a list like this:



A = [[1,2,3,4],[1,1,2,4],[1,2,3,4],[5,6,7,8],[1,4,3,4],[0,1,0,1],[0,0,0,0]]


I just want to delete or remove a any list. it have member of string or logical.
how i can do it.







python python-3.x algorithm list types






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 18:20









Daniel Mesejo

11.5k1924




11.5k1924










asked Nov 10 at 18:12









lyca

215




215












  • So you want to remove any lists that have False in them?
    – Ayxan
    Nov 10 at 18:16










  • yeap, I want to remove any type is not int or float from list.
    – lyca
    Nov 10 at 18:18




















  • So you want to remove any lists that have False in them?
    – Ayxan
    Nov 10 at 18:16










  • yeap, I want to remove any type is not int or float from list.
    – lyca
    Nov 10 at 18:18


















So you want to remove any lists that have False in them?
– Ayxan
Nov 10 at 18:16




So you want to remove any lists that have False in them?
– Ayxan
Nov 10 at 18:16












yeap, I want to remove any type is not int or float from list.
– lyca
Nov 10 at 18:18






yeap, I want to remove any type is not int or float from list.
– lyca
Nov 10 at 18:18














1 Answer
1






active

oldest

votes


















5














We can do this with list comprehension where we perform a filter with any(..) that checks if there is any element that is an instance of str or bool:



[sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]


this then yields:



>>> [sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]
[[1, 2, 3, 4], [1, 1, 2, 4], [1, 2, 3, 4], [5, 6, 7, 8], [1, 4, 3, 4], [0, 1, 0, 1], [0, 0, 0, 0]]





share|improve this answer





















  • what is meaning of e ?
    – lyca
    Nov 10 at 18:21










  • @lyca: the element in the generator, it enumerates over sublist with ... for e in sublist.
    – Willem Van Onsem
    Nov 10 at 18:22











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241969%2fhow-to-detect-logical-and-string-index-in-sub-list-and-delete-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














We can do this with list comprehension where we perform a filter with any(..) that checks if there is any element that is an instance of str or bool:



[sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]


this then yields:



>>> [sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]
[[1, 2, 3, 4], [1, 1, 2, 4], [1, 2, 3, 4], [5, 6, 7, 8], [1, 4, 3, 4], [0, 1, 0, 1], [0, 0, 0, 0]]





share|improve this answer





















  • what is meaning of e ?
    – lyca
    Nov 10 at 18:21










  • @lyca: the element in the generator, it enumerates over sublist with ... for e in sublist.
    – Willem Van Onsem
    Nov 10 at 18:22
















5














We can do this with list comprehension where we perform a filter with any(..) that checks if there is any element that is an instance of str or bool:



[sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]


this then yields:



>>> [sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]
[[1, 2, 3, 4], [1, 1, 2, 4], [1, 2, 3, 4], [5, 6, 7, 8], [1, 4, 3, 4], [0, 1, 0, 1], [0, 0, 0, 0]]





share|improve this answer





















  • what is meaning of e ?
    – lyca
    Nov 10 at 18:21










  • @lyca: the element in the generator, it enumerates over sublist with ... for e in sublist.
    – Willem Van Onsem
    Nov 10 at 18:22














5












5








5






We can do this with list comprehension where we perform a filter with any(..) that checks if there is any element that is an instance of str or bool:



[sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]


this then yields:



>>> [sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]
[[1, 2, 3, 4], [1, 1, 2, 4], [1, 2, 3, 4], [5, 6, 7, 8], [1, 4, 3, 4], [0, 1, 0, 1], [0, 0, 0, 0]]





share|improve this answer












We can do this with list comprehension where we perform a filter with any(..) that checks if there is any element that is an instance of str or bool:



[sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]


this then yields:



>>> [sublist for sublist in A if not any(isinstance(e, (str, bool)) for e in sublist)]
[[1, 2, 3, 4], [1, 1, 2, 4], [1, 2, 3, 4], [5, 6, 7, 8], [1, 4, 3, 4], [0, 1, 0, 1], [0, 0, 0, 0]]






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 18:16









Willem Van Onsem

143k16135227




143k16135227












  • what is meaning of e ?
    – lyca
    Nov 10 at 18:21










  • @lyca: the element in the generator, it enumerates over sublist with ... for e in sublist.
    – Willem Van Onsem
    Nov 10 at 18:22


















  • what is meaning of e ?
    – lyca
    Nov 10 at 18:21










  • @lyca: the element in the generator, it enumerates over sublist with ... for e in sublist.
    – Willem Van Onsem
    Nov 10 at 18:22
















what is meaning of e ?
– lyca
Nov 10 at 18:21




what is meaning of e ?
– lyca
Nov 10 at 18:21












@lyca: the element in the generator, it enumerates over sublist with ... for e in sublist.
– Willem Van Onsem
Nov 10 at 18:22




@lyca: the element in the generator, it enumerates over sublist with ... for e in sublist.
– Willem Van Onsem
Nov 10 at 18:22


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241969%2fhow-to-detect-logical-and-string-index-in-sub-list-and-delete-it%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini