Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6966765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:14:01+00:00 2026-05-27T16:14:01+00:00

I had a small requirement of making a specific attribute as primary key, such

  • 0

I had a small requirement of making a specific attribute as primary key, such that by using this attribute I want to access the other attributes of the same row. Could any one help me please.

Description:: I had 4 arrays and I want to retrieve the data in the arrays corresponding to the row I have selected.In simple terms I am using Python as a database and store the retrieve the values of other tuples basing on a specific column value.

import string
import sys
from Tkinter import *
import win32com.client

win = Tk()
win.title("Sorting the list of employees as of desire")
win.geometry("600x600+200+50")
win.resizable()

class Emp(object):
    def __init__(self):
        i = 0


        def save():            
            b = self.e.get()
            #print "The name of employee is", b
            n.append(b) 

            c = self.a.get()
            #print "The age of employee is", c
            ge.append(c)  

            idf = self.i.get()
            #print "The Ide of the Employee is ", id            
            idee.append(idf)  

            de = self.d.get()
            # print "The Designation of the Employee is ", de            
            desi.append(de) 

            #print "\n"


        def clear():
            self.e.delete(0, END)
            self.a.delete(0, END)
            self.i.delete(0, END)
            self.d.delete(0, END)

        n = []
        Label(text="Employee form ", font="Verdana 18 bold italic").pack()
        Name = Label(text="Name ", font="Verdana 10 bold ")
        Name.place(relx=0.1, rely=0.5)
        Name.pack()
        self.e = Entry(text="Enter the name of the employee ")
        self.e.place(relx=0.5, rely=0.5, anchor=CENTER)
        self.e.insert(0, "Name of Employee")
        self.e.pack()

        ge = []
        age = Label(text="Age ", font="Verdana 10 bold ")
        age.place(relx=0.1, rely=0.5)
        age.pack()
        self.a = Entry(text="Enter the age of the employee ")
        self.a.place(relx=0.5, rely=0.5, anchor=CENTER)
        self.a.insert(0, "Age of Employee")
        self.a.pack()

        idee = []
        ide = Label(text="ID ", font="Verdana 10 bold ")
        ide.place(relx=0.1, rely=0.5)
        ide.pack()
        self.i = Entry(text="Enter the ID of the employee ")
        self.i.place(relx=0.5, rely=0.5, anchor=CENTER)
        self.i.insert(0, "IDE of Employee")
        self.i.pack()


        desi = []
        des = Label(text="Designation ", font="Verdana 10 bold ")
        des.place(relx=0.1, rely=0.5)
        des.pack()
        self.d = Entry(text="The Designation of the employee ")
        self.d.place(relx=0.5, rely=0.5, anchor=CENTER)
        self.d.insert(0, "Designation of Employee")
        self.d.pack()

        def printf():
            global i 

            xyz = len(n)
            for i in range(0, xyz):
                print "Details are ::", "Name is :", n[i], "Age is : ", ge[i], "Employee Id is :", idee[i], "Designation is :", desi[i] 
                print "\n"

        def sorting():
            sor = raw_input("Enter a to sort from A or z to sort in reverse order")
            xyz = len(n)
            if sor == 'a' or'A' :
                n.sort()
                for i in range(0, xyz):
                    print "Details are ::", "Name is :", n[i]#, "Age is : ", ge[i], "Employee Id is :", idee[i], "Designation is :", desi[i] 
                    print "\n"
            elif sor == 'z' or 'Z':
                n.sort()
                print "Details are ::", "Name is :", n[i], "Age is : ", ge[i], "Employee Id is :", idee[i], "Designation is :", desi[i] 
                n.reverse()
                for i in range(0, xyz):
                    print "Details are ::", "Name is :", n[i]#, "Age is : ", ge[i], "Employee Id is :", idee[i], "Designation is :", desi[i] 
                    print "\n"

        btn = Button(text="Save ", font="verdana 12 ", command=save)
        btn.pack(fill=X, expand=YES)
        btn.place(relx=0.85, rely=0.06, anchor=CENTER)

        btnc = Button(text="Next", font="verdana 12 ", command=clear)
        btnc.pack(fill=X, expand=YES)
        btnc.place(relx=0.85, rely=0.90, anchor=CENTER)      

        btnp = Button(text="print", font="verdana 12 ", command=printf)
        btnp.pack(fill=X, expand=YES)
        btnp.place(relx=0.6, rely=0.9, anchor=CENTER)      

        btns = Button(text="Sort", font="verdana 12 ", command=sorting)
        btns.pack(fill=X, expand=YES)
        btns.place(relx=0.3, rely=0.9, anchor=CENTER)





abj = Emp()
win.mainloop()

This is my code. After storing all the values in the respective arrays.I want to sort them basing on name, to the code I have written the output I got is the sorted array of only the name attribute, Instead I want all the corresponding values also to be sorted.Please help me

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:14:02+00:00Added an answer on May 27, 2026 at 4:14 pm

    Replying to original question (it’s been erased):

    You could use a python dict: http://docs.python.org/library/stdtypes.html#dict.

    dataset = {}
    dataset['key1'] = (value_1_1, value_1_2, value_1_3, value_1_4)
    dataset['key2'] = (value_2_1, value_2_2, value_2_3, value_2_4)
    

    Then if you wanted the values associated with ‘key2’:

    row_of_interest = dataest['key2']
    

    In the context of your code, using a dict:

    More specifically, after seeing your code, one solution would be to change your save function to this:

    def save():
        name = self.e.get()
        age = self.a.get()
        employee_id = self.i.get()
        employee_designation = self.d.get()
        self.employees[name] = (age, employee_id, employee_designation)
    

    where employees is a dict. This gives you your primary key property stated in your question, but doesn’t give you easy access to sorted results as your code hints at.

    OR, using a list:

    def save():
        name = self.e.get()
        age = self.a.get()
        employee_id = self.i.get()
        employee_designation = self.d.get()
        self.employees.append((name, age, employee_id, employee_designation))
    

    where employees is a list, not a dict. Then you can use the sorted built-in function (http://docs.python.org/library/functions.html#sorted) combined with the operator module to get your sorted results:

    sorted(self.employees, key=operator.itemgetter(0), reverse=False)
    

    This gives you easy access to results sorted by the first element (the names), but doesn’t treat any of the attributes as a special primary key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had created a small app such that the image which is displaying should
I'm working on a class assignment that started small, so I had it all
Giving small background to my requirement and what i had accomplished so far: There
I am using a small java smtp library ( http://code.google.com/p/subethasmtp/ ), by this I
I had a small WTF moment this morning. Ths WTF can be summarized with
I want a small (< 30MB) standalone Windows executable (a single file) that creates
I remember one such popular hardware. It was small, had USB ports, etc. and
I had a requirement to create a small file utility class to run off
I had a small bug in a view and noticed that the view engine
I just got off a small project using a WCF/REST Web Service that used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.