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











up vote
1
down vote

favorite












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

















up vote
1
down vote

favorite












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















up vote
1
down vote

favorite









up vote
1
down vote

favorite











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

7,9741922




7,9741922










asked Nov 10 at 18:12









lyca

112




112












  • 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

















up vote
5
down vote













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',
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








up vote
5
down vote













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















up vote
5
down vote













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













up vote
5
down vote










up vote
5
down vote









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

140k16131222




140k16131222












  • 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



















































 


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







Popular posts from this blog

Full-time equivalent

さくらももこ

13 indicted, 8 arrested in Calif. drug cartel investigation