How to find mean of an array which has two elements in Python?











up vote
3
down vote

favorite
1












I need to find mean of an array which is like: [('a', 5), ('b', 2), ('a', 4), ('b', 6)]



Result should be like; [('a', 4.5), ('b', 4)]










share|improve this question




























    up vote
    3
    down vote

    favorite
    1












    I need to find mean of an array which is like: [('a', 5), ('b', 2), ('a', 4), ('b', 6)]



    Result should be like; [('a', 4.5), ('b', 4)]










    share|improve this question


























      up vote
      3
      down vote

      favorite
      1









      up vote
      3
      down vote

      favorite
      1






      1





      I need to find mean of an array which is like: [('a', 5), ('b', 2), ('a', 4), ('b', 6)]



      Result should be like; [('a', 4.5), ('b', 4)]










      share|improve this question















      I need to find mean of an array which is like: [('a', 5), ('b', 2), ('a', 4), ('b', 6)]



      Result should be like; [('a', 4.5), ('b', 4)]







      python numpy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      Willem Van Onsem

      138k16129220




      138k16129220










      asked yesterday









      bukowski

      108215




      108215
























          5 Answers
          5






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          Raw solution without additional libraries could look like this:



          def mean(l):
          result = {}
          for key, value in l:
          if key not in result:
          result[key] =
          result[key].append(value)

          return [(k, sum(v)/len(v)) for k, v in result.items()]

          lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
          m = mean(lst)

          print(m)
          # [('a', 4.5), ('b', 4.0)]





          share|improve this answer




























            up vote
            3
            down vote













            You can put all your tuples in a defaultdict, using the first value to group them into a list and then calculate the mean:



            from collections import defaultdict

            d = defaultdict(list)

            for key,value in [('a', 5), ('b', 2), ('a', 4), ('b', 6)]:
            d[key].append(value)

            mean =

            for k,values in d.items():
            # mean.append((k,sum(values)/float(len(values)))) #python 2
            mean.append((k,sum(values)/len(values)))

            print(mean) # [('a', 4.5), ('b', 4.0)]





            share|improve this answer




























              up vote
              2
              down vote













              We can use pandas for this:



              import pandas as pd

              pd.DataFrame(data).groupby(0)[1].mean().to_dict()


              this will give us:



              >>> pd.DataFrame(data).groupby(0)[1].mean().to_dict()
              {'a': 4.5, 'b': 4.0}


              or we can convert this to a list of 2-tuples with:



              list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())


              which gives:



              >>> list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())
              [('a', 4.5), ('b', 4.0)]


              The above is thus more a "declarative" approach: we specify what we want, not much how we want to do this.






              share|improve this answer




























                up vote
                2
                down vote













                You can collect the numbers with a collections.defaultdict(), then apply statistics.mean() on each group of numbers:



                from statistics import mean
                from collections import defaultdict

                lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]

                d = defaultdict(list)
                for k, v in lst:
                d[k].append(v)

                means = [(k, mean(v)) for k, v in d.items()]

                print(means)
                # [('a', 4.5), ('b', 4)]


                You can also use itertools.groupby() to group the tuples:



                from statistics import mean
                from itertools import groupby
                from operator import itemgetter

                lst = [("a", 5), ("b", 2), ("a", 4), ("b", 6)]

                means = [
                (k, mean(map(itemgetter(1), g)))
                for k, g in groupby(sorted(lst, key=itemgetter(0)), key=itemgetter(0))
                ]

                print(means)
                [('a', 4.5), ('b', 4)]





                share|improve this answer























                • Hi thanks for the answer I'm giving it a try but I wonder if d = deafultdict(list) shouldn't be d = deafultdict(lst) ?
                  – bukowski
                  yesterday






                • 2




                  @bukowski: no, defaultdict takes a callable that constructs elements in case it is missing. We do not want to insert the data by default.
                  – Willem Van Onsem
                  yesterday


















                up vote
                2
                down vote













                If you wish, you can also try the below reusable code (without using any external libraries).



                >>> def get_mean(l):
                ... d = {}
                ... for k, v in l:
                ... if k in d:
                ... d[k].append(v)
                ... else:
                ... d[k] = [v]
                ... result = [(k, sum(d[k])/len(d[k])) for k in d]
                ... return result
                ...
                >>> l = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
                >>> new_l = get_mean(l)
                >>> new_l
                [('a', 4.5), ('b', 4.0)]
                >>>





                share|improve this answer





















                • Grouping with setdefault() would be cleaner IMO. You avoid the if/else that way.
                  – RoadRunner
                  yesterday













                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%2f53238083%2fhow-to-find-mean-of-an-array-which-has-two-elements-in-python%23new-answer', 'question_page');
                }
                );

                Post as a guest
































                5 Answers
                5






                active

                oldest

                votes








                5 Answers
                5






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes








                up vote
                2
                down vote



                accepted










                Raw solution without additional libraries could look like this:



                def mean(l):
                result = {}
                for key, value in l:
                if key not in result:
                result[key] =
                result[key].append(value)

                return [(k, sum(v)/len(v)) for k, v in result.items()]

                lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
                m = mean(lst)

                print(m)
                # [('a', 4.5), ('b', 4.0)]





                share|improve this answer

























                  up vote
                  2
                  down vote



                  accepted










                  Raw solution without additional libraries could look like this:



                  def mean(l):
                  result = {}
                  for key, value in l:
                  if key not in result:
                  result[key] =
                  result[key].append(value)

                  return [(k, sum(v)/len(v)) for k, v in result.items()]

                  lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
                  m = mean(lst)

                  print(m)
                  # [('a', 4.5), ('b', 4.0)]





                  share|improve this answer























                    up vote
                    2
                    down vote



                    accepted







                    up vote
                    2
                    down vote



                    accepted






                    Raw solution without additional libraries could look like this:



                    def mean(l):
                    result = {}
                    for key, value in l:
                    if key not in result:
                    result[key] =
                    result[key].append(value)

                    return [(k, sum(v)/len(v)) for k, v in result.items()]

                    lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
                    m = mean(lst)

                    print(m)
                    # [('a', 4.5), ('b', 4.0)]





                    share|improve this answer












                    Raw solution without additional libraries could look like this:



                    def mean(l):
                    result = {}
                    for key, value in l:
                    if key not in result:
                    result[key] =
                    result[key].append(value)

                    return [(k, sum(v)/len(v)) for k, v in result.items()]

                    lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
                    m = mean(lst)

                    print(m)
                    # [('a', 4.5), ('b', 4.0)]






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered yesterday









                    Looioe

                    845




                    845
























                        up vote
                        3
                        down vote













                        You can put all your tuples in a defaultdict, using the first value to group them into a list and then calculate the mean:



                        from collections import defaultdict

                        d = defaultdict(list)

                        for key,value in [('a', 5), ('b', 2), ('a', 4), ('b', 6)]:
                        d[key].append(value)

                        mean =

                        for k,values in d.items():
                        # mean.append((k,sum(values)/float(len(values)))) #python 2
                        mean.append((k,sum(values)/len(values)))

                        print(mean) # [('a', 4.5), ('b', 4.0)]





                        share|improve this answer

























                          up vote
                          3
                          down vote













                          You can put all your tuples in a defaultdict, using the first value to group them into a list and then calculate the mean:



                          from collections import defaultdict

                          d = defaultdict(list)

                          for key,value in [('a', 5), ('b', 2), ('a', 4), ('b', 6)]:
                          d[key].append(value)

                          mean =

                          for k,values in d.items():
                          # mean.append((k,sum(values)/float(len(values)))) #python 2
                          mean.append((k,sum(values)/len(values)))

                          print(mean) # [('a', 4.5), ('b', 4.0)]





                          share|improve this answer























                            up vote
                            3
                            down vote










                            up vote
                            3
                            down vote









                            You can put all your tuples in a defaultdict, using the first value to group them into a list and then calculate the mean:



                            from collections import defaultdict

                            d = defaultdict(list)

                            for key,value in [('a', 5), ('b', 2), ('a', 4), ('b', 6)]:
                            d[key].append(value)

                            mean =

                            for k,values in d.items():
                            # mean.append((k,sum(values)/float(len(values)))) #python 2
                            mean.append((k,sum(values)/len(values)))

                            print(mean) # [('a', 4.5), ('b', 4.0)]





                            share|improve this answer












                            You can put all your tuples in a defaultdict, using the first value to group them into a list and then calculate the mean:



                            from collections import defaultdict

                            d = defaultdict(list)

                            for key,value in [('a', 5), ('b', 2), ('a', 4), ('b', 6)]:
                            d[key].append(value)

                            mean =

                            for k,values in d.items():
                            # mean.append((k,sum(values)/float(len(values)))) #python 2
                            mean.append((k,sum(values)/len(values)))

                            print(mean) # [('a', 4.5), ('b', 4.0)]






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered yesterday









                            Patrick Artner

                            17.5k51739




                            17.5k51739






















                                up vote
                                2
                                down vote













                                We can use pandas for this:



                                import pandas as pd

                                pd.DataFrame(data).groupby(0)[1].mean().to_dict()


                                this will give us:



                                >>> pd.DataFrame(data).groupby(0)[1].mean().to_dict()
                                {'a': 4.5, 'b': 4.0}


                                or we can convert this to a list of 2-tuples with:



                                list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())


                                which gives:



                                >>> list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())
                                [('a', 4.5), ('b', 4.0)]


                                The above is thus more a "declarative" approach: we specify what we want, not much how we want to do this.






                                share|improve this answer

























                                  up vote
                                  2
                                  down vote













                                  We can use pandas for this:



                                  import pandas as pd

                                  pd.DataFrame(data).groupby(0)[1].mean().to_dict()


                                  this will give us:



                                  >>> pd.DataFrame(data).groupby(0)[1].mean().to_dict()
                                  {'a': 4.5, 'b': 4.0}


                                  or we can convert this to a list of 2-tuples with:



                                  list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())


                                  which gives:



                                  >>> list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())
                                  [('a', 4.5), ('b', 4.0)]


                                  The above is thus more a "declarative" approach: we specify what we want, not much how we want to do this.






                                  share|improve this answer























                                    up vote
                                    2
                                    down vote










                                    up vote
                                    2
                                    down vote









                                    We can use pandas for this:



                                    import pandas as pd

                                    pd.DataFrame(data).groupby(0)[1].mean().to_dict()


                                    this will give us:



                                    >>> pd.DataFrame(data).groupby(0)[1].mean().to_dict()
                                    {'a': 4.5, 'b': 4.0}


                                    or we can convert this to a list of 2-tuples with:



                                    list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())


                                    which gives:



                                    >>> list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())
                                    [('a', 4.5), ('b', 4.0)]


                                    The above is thus more a "declarative" approach: we specify what we want, not much how we want to do this.






                                    share|improve this answer












                                    We can use pandas for this:



                                    import pandas as pd

                                    pd.DataFrame(data).groupby(0)[1].mean().to_dict()


                                    this will give us:



                                    >>> pd.DataFrame(data).groupby(0)[1].mean().to_dict()
                                    {'a': 4.5, 'b': 4.0}


                                    or we can convert this to a list of 2-tuples with:



                                    list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())


                                    which gives:



                                    >>> list(pd.DataFrame(data).groupby(0)[1].mean().to_dict().items())
                                    [('a', 4.5), ('b', 4.0)]


                                    The above is thus more a "declarative" approach: we specify what we want, not much how we want to do this.







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered yesterday









                                    Willem Van Onsem

                                    138k16129220




                                    138k16129220






















                                        up vote
                                        2
                                        down vote













                                        You can collect the numbers with a collections.defaultdict(), then apply statistics.mean() on each group of numbers:



                                        from statistics import mean
                                        from collections import defaultdict

                                        lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]

                                        d = defaultdict(list)
                                        for k, v in lst:
                                        d[k].append(v)

                                        means = [(k, mean(v)) for k, v in d.items()]

                                        print(means)
                                        # [('a', 4.5), ('b', 4)]


                                        You can also use itertools.groupby() to group the tuples:



                                        from statistics import mean
                                        from itertools import groupby
                                        from operator import itemgetter

                                        lst = [("a", 5), ("b", 2), ("a", 4), ("b", 6)]

                                        means = [
                                        (k, mean(map(itemgetter(1), g)))
                                        for k, g in groupby(sorted(lst, key=itemgetter(0)), key=itemgetter(0))
                                        ]

                                        print(means)
                                        [('a', 4.5), ('b', 4)]





                                        share|improve this answer























                                        • Hi thanks for the answer I'm giving it a try but I wonder if d = deafultdict(list) shouldn't be d = deafultdict(lst) ?
                                          – bukowski
                                          yesterday






                                        • 2




                                          @bukowski: no, defaultdict takes a callable that constructs elements in case it is missing. We do not want to insert the data by default.
                                          – Willem Van Onsem
                                          yesterday















                                        up vote
                                        2
                                        down vote













                                        You can collect the numbers with a collections.defaultdict(), then apply statistics.mean() on each group of numbers:



                                        from statistics import mean
                                        from collections import defaultdict

                                        lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]

                                        d = defaultdict(list)
                                        for k, v in lst:
                                        d[k].append(v)

                                        means = [(k, mean(v)) for k, v in d.items()]

                                        print(means)
                                        # [('a', 4.5), ('b', 4)]


                                        You can also use itertools.groupby() to group the tuples:



                                        from statistics import mean
                                        from itertools import groupby
                                        from operator import itemgetter

                                        lst = [("a", 5), ("b", 2), ("a", 4), ("b", 6)]

                                        means = [
                                        (k, mean(map(itemgetter(1), g)))
                                        for k, g in groupby(sorted(lst, key=itemgetter(0)), key=itemgetter(0))
                                        ]

                                        print(means)
                                        [('a', 4.5), ('b', 4)]





                                        share|improve this answer























                                        • Hi thanks for the answer I'm giving it a try but I wonder if d = deafultdict(list) shouldn't be d = deafultdict(lst) ?
                                          – bukowski
                                          yesterday






                                        • 2




                                          @bukowski: no, defaultdict takes a callable that constructs elements in case it is missing. We do not want to insert the data by default.
                                          – Willem Van Onsem
                                          yesterday













                                        up vote
                                        2
                                        down vote










                                        up vote
                                        2
                                        down vote









                                        You can collect the numbers with a collections.defaultdict(), then apply statistics.mean() on each group of numbers:



                                        from statistics import mean
                                        from collections import defaultdict

                                        lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]

                                        d = defaultdict(list)
                                        for k, v in lst:
                                        d[k].append(v)

                                        means = [(k, mean(v)) for k, v in d.items()]

                                        print(means)
                                        # [('a', 4.5), ('b', 4)]


                                        You can also use itertools.groupby() to group the tuples:



                                        from statistics import mean
                                        from itertools import groupby
                                        from operator import itemgetter

                                        lst = [("a", 5), ("b", 2), ("a", 4), ("b", 6)]

                                        means = [
                                        (k, mean(map(itemgetter(1), g)))
                                        for k, g in groupby(sorted(lst, key=itemgetter(0)), key=itemgetter(0))
                                        ]

                                        print(means)
                                        [('a', 4.5), ('b', 4)]





                                        share|improve this answer














                                        You can collect the numbers with a collections.defaultdict(), then apply statistics.mean() on each group of numbers:



                                        from statistics import mean
                                        from collections import defaultdict

                                        lst = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]

                                        d = defaultdict(list)
                                        for k, v in lst:
                                        d[k].append(v)

                                        means = [(k, mean(v)) for k, v in d.items()]

                                        print(means)
                                        # [('a', 4.5), ('b', 4)]


                                        You can also use itertools.groupby() to group the tuples:



                                        from statistics import mean
                                        from itertools import groupby
                                        from operator import itemgetter

                                        lst = [("a", 5), ("b", 2), ("a", 4), ("b", 6)]

                                        means = [
                                        (k, mean(map(itemgetter(1), g)))
                                        for k, g in groupby(sorted(lst, key=itemgetter(0)), key=itemgetter(0))
                                        ]

                                        print(means)
                                        [('a', 4.5), ('b', 4)]






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited yesterday

























                                        answered yesterday









                                        RoadRunner

                                        8,49731137




                                        8,49731137












                                        • Hi thanks for the answer I'm giving it a try but I wonder if d = deafultdict(list) shouldn't be d = deafultdict(lst) ?
                                          – bukowski
                                          yesterday






                                        • 2




                                          @bukowski: no, defaultdict takes a callable that constructs elements in case it is missing. We do not want to insert the data by default.
                                          – Willem Van Onsem
                                          yesterday


















                                        • Hi thanks for the answer I'm giving it a try but I wonder if d = deafultdict(list) shouldn't be d = deafultdict(lst) ?
                                          – bukowski
                                          yesterday






                                        • 2




                                          @bukowski: no, defaultdict takes a callable that constructs elements in case it is missing. We do not want to insert the data by default.
                                          – Willem Van Onsem
                                          yesterday
















                                        Hi thanks for the answer I'm giving it a try but I wonder if d = deafultdict(list) shouldn't be d = deafultdict(lst) ?
                                        – bukowski
                                        yesterday




                                        Hi thanks for the answer I'm giving it a try but I wonder if d = deafultdict(list) shouldn't be d = deafultdict(lst) ?
                                        – bukowski
                                        yesterday




                                        2




                                        2




                                        @bukowski: no, defaultdict takes a callable that constructs elements in case it is missing. We do not want to insert the data by default.
                                        – Willem Van Onsem
                                        yesterday




                                        @bukowski: no, defaultdict takes a callable that constructs elements in case it is missing. We do not want to insert the data by default.
                                        – Willem Van Onsem
                                        yesterday










                                        up vote
                                        2
                                        down vote













                                        If you wish, you can also try the below reusable code (without using any external libraries).



                                        >>> def get_mean(l):
                                        ... d = {}
                                        ... for k, v in l:
                                        ... if k in d:
                                        ... d[k].append(v)
                                        ... else:
                                        ... d[k] = [v]
                                        ... result = [(k, sum(d[k])/len(d[k])) for k in d]
                                        ... return result
                                        ...
                                        >>> l = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
                                        >>> new_l = get_mean(l)
                                        >>> new_l
                                        [('a', 4.5), ('b', 4.0)]
                                        >>>





                                        share|improve this answer





















                                        • Grouping with setdefault() would be cleaner IMO. You avoid the if/else that way.
                                          – RoadRunner
                                          yesterday

















                                        up vote
                                        2
                                        down vote













                                        If you wish, you can also try the below reusable code (without using any external libraries).



                                        >>> def get_mean(l):
                                        ... d = {}
                                        ... for k, v in l:
                                        ... if k in d:
                                        ... d[k].append(v)
                                        ... else:
                                        ... d[k] = [v]
                                        ... result = [(k, sum(d[k])/len(d[k])) for k in d]
                                        ... return result
                                        ...
                                        >>> l = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
                                        >>> new_l = get_mean(l)
                                        >>> new_l
                                        [('a', 4.5), ('b', 4.0)]
                                        >>>





                                        share|improve this answer





















                                        • Grouping with setdefault() would be cleaner IMO. You avoid the if/else that way.
                                          – RoadRunner
                                          yesterday















                                        up vote
                                        2
                                        down vote










                                        up vote
                                        2
                                        down vote









                                        If you wish, you can also try the below reusable code (without using any external libraries).



                                        >>> def get_mean(l):
                                        ... d = {}
                                        ... for k, v in l:
                                        ... if k in d:
                                        ... d[k].append(v)
                                        ... else:
                                        ... d[k] = [v]
                                        ... result = [(k, sum(d[k])/len(d[k])) for k in d]
                                        ... return result
                                        ...
                                        >>> l = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
                                        >>> new_l = get_mean(l)
                                        >>> new_l
                                        [('a', 4.5), ('b', 4.0)]
                                        >>>





                                        share|improve this answer












                                        If you wish, you can also try the below reusable code (without using any external libraries).



                                        >>> def get_mean(l):
                                        ... d = {}
                                        ... for k, v in l:
                                        ... if k in d:
                                        ... d[k].append(v)
                                        ... else:
                                        ... d[k] = [v]
                                        ... result = [(k, sum(d[k])/len(d[k])) for k in d]
                                        ... return result
                                        ...
                                        >>> l = [('a', 5), ('b', 2), ('a', 4), ('b', 6)]
                                        >>> new_l = get_mean(l)
                                        >>> new_l
                                        [('a', 4.5), ('b', 4.0)]
                                        >>>






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered yesterday









                                        hygull

                                        2,67311126




                                        2,67311126












                                        • Grouping with setdefault() would be cleaner IMO. You avoid the if/else that way.
                                          – RoadRunner
                                          yesterday




















                                        • Grouping with setdefault() would be cleaner IMO. You avoid the if/else that way.
                                          – RoadRunner
                                          yesterday


















                                        Grouping with setdefault() would be cleaner IMO. You avoid the if/else that way.
                                        – RoadRunner
                                        yesterday






                                        Grouping with setdefault() would be cleaner IMO. You avoid the if/else that way.
                                        – RoadRunner
                                        yesterday




















                                         

                                        draft saved


                                        draft discarded



















































                                         


                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238083%2fhow-to-find-mean-of-an-array-which-has-two-elements-in-python%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest




















































































                                        Popular posts from this blog

                                        Florida Star v. B. J. F.

                                        Error while running script in elastic search , gateway timeout

                                        Adding quotations to stringified JSON object values