yield a dictionary into a table format












0















I have a excel file from which I am extracting a column and making a list out of it. Lets say the list looks like this:



list_main = [1,2,3,4,5,6] #main list



I am showing this list in a browser using flask. After this I am checking items in a list exist in database or not and if they exist then whether or not they a have a price.



For that I was previously making three lists and returning the output to browser. After which I thought that the items would be repetitive because the other two lists were just a subset of main list. Like this:



sub_list1 = [1,2,4,5] # subset of mainlist
sublist2 = [1,2] # subset of sublist1


To reduce all the calculations and processing time I want to make a dictionary and yielding the output as processed. Like this:



dict_main = {"1":[yes,yes], "2":[yes,yes], "3":[no,no], "4":[yes,no],...}
#output
1 yes yes
2 yes yes
3 no no
4 yes no
5 yes no
6 no no


This is what I have tired so far:



@app.route('/upload', methods=['GET'])
def auee():
list_main = [1,2,3,4,5,6] #list I got from excel
found = yes
def events():
for i in list_mian:
data1 = pd.read_sql("DATABASE QUERY", engine)
new_data = data1['item_id'].drop_duplicates().values.tolist()
print('n'.join(str(p.rstrip()) for p in new_data ))
for row in new_data:
if row.rstrip() not in listset:
listset.append(row.rstrip())
yield "data: %s %snn" % (i,row.rstrip())

return Response(events(), content_type='text/event-stream')


The above program just prints main list but will only print items that exist in sublist as it is inside another loop.



This was the reason I choose dictionary. What could be the most efficient way to yield a dictionary i.e stream the output as processed.










share|improve this question





























    0















    I have a excel file from which I am extracting a column and making a list out of it. Lets say the list looks like this:



    list_main = [1,2,3,4,5,6] #main list



    I am showing this list in a browser using flask. After this I am checking items in a list exist in database or not and if they exist then whether or not they a have a price.



    For that I was previously making three lists and returning the output to browser. After which I thought that the items would be repetitive because the other two lists were just a subset of main list. Like this:



    sub_list1 = [1,2,4,5] # subset of mainlist
    sublist2 = [1,2] # subset of sublist1


    To reduce all the calculations and processing time I want to make a dictionary and yielding the output as processed. Like this:



    dict_main = {"1":[yes,yes], "2":[yes,yes], "3":[no,no], "4":[yes,no],...}
    #output
    1 yes yes
    2 yes yes
    3 no no
    4 yes no
    5 yes no
    6 no no


    This is what I have tired so far:



    @app.route('/upload', methods=['GET'])
    def auee():
    list_main = [1,2,3,4,5,6] #list I got from excel
    found = yes
    def events():
    for i in list_mian:
    data1 = pd.read_sql("DATABASE QUERY", engine)
    new_data = data1['item_id'].drop_duplicates().values.tolist()
    print('n'.join(str(p.rstrip()) for p in new_data ))
    for row in new_data:
    if row.rstrip() not in listset:
    listset.append(row.rstrip())
    yield "data: %s %snn" % (i,row.rstrip())

    return Response(events(), content_type='text/event-stream')


    The above program just prints main list but will only print items that exist in sublist as it is inside another loop.



    This was the reason I choose dictionary. What could be the most efficient way to yield a dictionary i.e stream the output as processed.










    share|improve this question



























      0












      0








      0








      I have a excel file from which I am extracting a column and making a list out of it. Lets say the list looks like this:



      list_main = [1,2,3,4,5,6] #main list



      I am showing this list in a browser using flask. After this I am checking items in a list exist in database or not and if they exist then whether or not they a have a price.



      For that I was previously making three lists and returning the output to browser. After which I thought that the items would be repetitive because the other two lists were just a subset of main list. Like this:



      sub_list1 = [1,2,4,5] # subset of mainlist
      sublist2 = [1,2] # subset of sublist1


      To reduce all the calculations and processing time I want to make a dictionary and yielding the output as processed. Like this:



      dict_main = {"1":[yes,yes], "2":[yes,yes], "3":[no,no], "4":[yes,no],...}
      #output
      1 yes yes
      2 yes yes
      3 no no
      4 yes no
      5 yes no
      6 no no


      This is what I have tired so far:



      @app.route('/upload', methods=['GET'])
      def auee():
      list_main = [1,2,3,4,5,6] #list I got from excel
      found = yes
      def events():
      for i in list_mian:
      data1 = pd.read_sql("DATABASE QUERY", engine)
      new_data = data1['item_id'].drop_duplicates().values.tolist()
      print('n'.join(str(p.rstrip()) for p in new_data ))
      for row in new_data:
      if row.rstrip() not in listset:
      listset.append(row.rstrip())
      yield "data: %s %snn" % (i,row.rstrip())

      return Response(events(), content_type='text/event-stream')


      The above program just prints main list but will only print items that exist in sublist as it is inside another loop.



      This was the reason I choose dictionary. What could be the most efficient way to yield a dictionary i.e stream the output as processed.










      share|improve this question
















      I have a excel file from which I am extracting a column and making a list out of it. Lets say the list looks like this:



      list_main = [1,2,3,4,5,6] #main list



      I am showing this list in a browser using flask. After this I am checking items in a list exist in database or not and if they exist then whether or not they a have a price.



      For that I was previously making three lists and returning the output to browser. After which I thought that the items would be repetitive because the other two lists were just a subset of main list. Like this:



      sub_list1 = [1,2,4,5] # subset of mainlist
      sublist2 = [1,2] # subset of sublist1


      To reduce all the calculations and processing time I want to make a dictionary and yielding the output as processed. Like this:



      dict_main = {"1":[yes,yes], "2":[yes,yes], "3":[no,no], "4":[yes,no],...}
      #output
      1 yes yes
      2 yes yes
      3 no no
      4 yes no
      5 yes no
      6 no no


      This is what I have tired so far:



      @app.route('/upload', methods=['GET'])
      def auee():
      list_main = [1,2,3,4,5,6] #list I got from excel
      found = yes
      def events():
      for i in list_mian:
      data1 = pd.read_sql("DATABASE QUERY", engine)
      new_data = data1['item_id'].drop_duplicates().values.tolist()
      print('n'.join(str(p.rstrip()) for p in new_data ))
      for row in new_data:
      if row.rstrip() not in listset:
      listset.append(row.rstrip())
      yield "data: %s %snn" % (i,row.rstrip())

      return Response(events(), content_type='text/event-stream')


      The above program just prints main list but will only print items that exist in sublist as it is inside another loop.



      This was the reason I choose dictionary. What could be the most efficient way to yield a dictionary i.e stream the output as processed.







      python python-3.x






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 18:40









      Torxed

      13.8k105790




      13.8k105790










      asked Nov 15 '18 at 18:36









      Duck_dragonDuck_dragon

      768




      768
























          0






          active

          oldest

          votes











          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%2f53325912%2fyield-a-dictionary-into-a-table-format%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325912%2fyield-a-dictionary-into-a-table-format%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

          List item for chat from Array inside array React Native

          Jo Brand

          Thiostrepton