count an element in a list with list inside in python [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • Nested List and count()

    7 answers




I have a list with one list inside and I would like to count how many times is one element repeat. for example:



list = ['a','b','c',['a','d']]
find = 'a'
list.count(find)


The ouptput is 1, but I'm looking for 2.



There is any easy way to do it?



thanks










share|improve this question













marked as duplicate by jpp list
Users with the  list badge can single-handedly close list questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 9 at 11:16


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    up vote
    0
    down vote

    favorite













    This question already has an answer here:




    • Nested List and count()

      7 answers




    I have a list with one list inside and I would like to count how many times is one element repeat. for example:



    list = ['a','b','c',['a','d']]
    find = 'a'
    list.count(find)


    The ouptput is 1, but I'm looking for 2.



    There is any easy way to do it?



    thanks










    share|improve this question













    marked as duplicate by jpp list
    Users with the  list badge can single-handedly close list questions as duplicates and reopen them as needed.

    StackExchange.ready(function() {
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function() {
    $hover.showInfoMessage('', {
    messageElement: $msg.clone().show(),
    transient: false,
    position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
    dismissable: false,
    relativeToBody: true
    });
    },
    function() {
    StackExchange.helpers.removeMessages();
    }
    );
    });
    });
    Nov 9 at 11:16


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite












      This question already has an answer here:




      • Nested List and count()

        7 answers




      I have a list with one list inside and I would like to count how many times is one element repeat. for example:



      list = ['a','b','c',['a','d']]
      find = 'a'
      list.count(find)


      The ouptput is 1, but I'm looking for 2.



      There is any easy way to do it?



      thanks










      share|improve this question














      This question already has an answer here:




      • Nested List and count()

        7 answers




      I have a list with one list inside and I would like to count how many times is one element repeat. for example:



      list = ['a','b','c',['a','d']]
      find = 'a'
      list.count(find)


      The ouptput is 1, but I'm looking for 2.



      There is any easy way to do it?



      thanks





      This question already has an answer here:




      • Nested List and count()

        7 answers








      python list count






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 11:14









      Alberto Aguilera

      354




      354




      marked as duplicate by jpp list
      Users with the  list badge can single-handedly close list questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 9 at 11:16


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by jpp list
      Users with the  list badge can single-handedly close list questions as duplicates and reopen them as needed.

      StackExchange.ready(function() {
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function() {
      $hover.showInfoMessage('', {
      messageElement: $msg.clone().show(),
      transient: false,
      position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
      dismissable: false,
      relativeToBody: true
      });
      },
      function() {
      StackExchange.helpers.removeMessages();
      }
      );
      });
      });
      Nov 9 at 11:16


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          Archive with chain.from_iterable



          from itertools import chain
          print(list(chain.from_iterable(lst)).count('a'))


          First make your list flatten and get the count.






          share|improve this answer




























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            Archive with chain.from_iterable



            from itertools import chain
            print(list(chain.from_iterable(lst)).count('a'))


            First make your list flatten and get the count.






            share|improve this answer

























              up vote
              0
              down vote



              accepted










              Archive with chain.from_iterable



              from itertools import chain
              print(list(chain.from_iterable(lst)).count('a'))


              First make your list flatten and get the count.






              share|improve this answer























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                Archive with chain.from_iterable



                from itertools import chain
                print(list(chain.from_iterable(lst)).count('a'))


                First make your list flatten and get the count.






                share|improve this answer












                Archive with chain.from_iterable



                from itertools import chain
                print(list(chain.from_iterable(lst)).count('a'))


                First make your list flatten and get the count.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 9 at 11:24









                Vikas Damodar

                1,9391520




                1,9391520















                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()