title: comparing value of two list python django?
body: <p>I have a two list coming from my views and I am comparing them and checking the values which match on a multi select drop-down. But the logic seems to work fine but it tends to multiply the data coming in multi select.</p>
  
  <pre><code> &lt;div class="form-group"&gt;
      &lt;label class="col-sm-4 control-label text_left"&gt;University &lt;span class="text-danger"&gt;*&lt;/span&gt;&lt;/label&gt;
      &lt;div class="col-sm-8"&gt;
          &lt;select class="form-control" value="university_all_list.id" name="universityId"
                  id="universityName" required&gt;
              &lt;option&gt;Select&lt;/option&gt;
  
              {% for university_name in university_all_list %}
                  {% for id in university_ids_list %}
                  {% if  id == university_name.id %}
                      &lt;option value="{{ university_name.id }}"
                              selected&gt;{{ university_name.name }}&lt;/option&gt;
                  {% else %}
                      &lt;option value="{{ university_name.id }}"&gt;{{ university_name.name }}&lt;/option&gt;
                  {% endif %}
              {% endfor %}
              {% endfor %}
          &lt;/select&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Any solution for this that it doesn't multiply my data in drop-down. I know I am using multiple for loop it is because of that,but what could be the solution for that.</p>
  
  <p>my views:</p>
  
  <pre><code>@login_required
  @csrf_exempt
  @cms_user_edit_decorator
  def admin_user_edit(request, cms_user_id=None):
      university_ids_list = []
      university_ids ={}
      university_all_list = Universities.objects.using('cms').all()
      master_cms_user_type_list = MasterCmsUserTypes.objects.all()
      cms_user = CmsUser.objects.get(userId=cms_user_id)
      school_university_mapping = SchoolAdminUniversityMappings.objects.filter(userId=cms_user)
      for university_ids in school_university_mapping:
          university_ids_list.append(university_ids.universityId)
      print university_ids_list
     # zip_list = zip(A, cycle(B)) if len(A) &gt; len(B) else zip(cycle(A), B)
      user_obj = {}
      user_showing = 'edit'
      if cms_user_id is not None:
          user_showing = 'edit'
          user_obj = User.objects.get(id=cms_user_id)
          if request.method == 'POST':
              first_name = request.POST.get('firstName').strip()
              last_name = request.POST.get('lastName').strip()
              username = request.POST.get('username').strip()
              email = request.POST.get('email').strip()
              status = request.POST.get('status')
              university = request.POST.getlist('universityId')
              print 'hulu lulu'
              print university
              staff = False
              superUser = False
              if status is None or status == '':
                  status = False
              else:
                  status = True
              if user_obj.email == email:
                  if user_obj.username == username:
                      if cms_user_id:
                          user_obj = User.objects.get(id=cms_user_id)
                          user_obj.first_name = first_name
                          user_obj.last_name = last_name
                          user_obj.email = email
                          user_obj.username = username
                          user_obj.is_active = status
                          user_obj.is_staff = staff
                          user_obj.is_superuser = superUser
                          user_obj.save()
                          messages.success(request, 'Successfully update to the Admin User')
                          return redirect('cms:admin-user-list')
                  else:
                      if User.objects.filter(username=username).exists():
                          messages.error(request, 'username already registered')
                      elif cms_user_id:
                          user_obj = User.objects.get(id=cms_user_id)
                          user_obj.first_name = first_name
                          user_obj.last_name = last_name
                          user_obj.email = email
                          user_obj.username = username
                          user_obj.is_active = status
                          user_obj.is_staff = staff
                          user_obj.is_superuser = superUser
                          user_obj.save()
                          messages.success(request, 'Successfully update to the Admin User')
                          return redirect('cms:admin-user-list')
              else:
                  if User.objects.filter(email=email).exists():
                      messages.error(request, 'email already exists')
                  elif cms_user_id:
                      user_obj = User.objects.get(id=cms_user_id)
                      user_obj.first_name = first_name
                      user_obj.last_name = last_name
                      user_obj.email = email
                      user_obj.username = username
                      user_obj.is_active = status
                      user_obj.is_staff = staff
                      user_obj.is_superuser = superUser
                      user_obj.save()
                      messages.success(request, 'Successfully update to the Admin User')
                      return redirect('cms:admin-user-list')
      return render(request, 'templates/admin_user_management/admin_user_edit.html', {
          'user_obj': user_obj,
          'user_showing': user_showing, 'master_cms_user_type_list': master_cms_user_type_list,
          'cms_user': cms_user,'university_all_list':university_all_list,'university_ids_list':university_ids_list,'list':list
      })
  </code></pre>