- 2

j,k = { 'w' : 'work' , 'k' : ' kite'}

Please tell what type of object it is, and how can access its values

17th May 2022, 3:50 PM
Subhash Devda
Subhash Devda - avatar
14 Answers
+ 4
Nuhu Abdul Bashit , please do not post a new question / thread inside an exising thread of a other user.
19th May 2022, 2:28 PM
Lothar
Lothar - avatar
+ 3
Subhash Devda , by using the code: j,k = { 'w' : 'work' , 'k' : ' kite'} we will store the key 'w' in variable 'j', and key 'k' in variable 'k' if we wanted to get the values stored in the variables instead of the keys, we need this code: j,k = { 'w' : 'work' , 'k' : ' kite'}.values() we will store the value 'work' in variable 'j', and the value 'kite' in variable 'k'
18th May 2022, 2:55 PM
Lothar
Lothar - avatar
+ 2
Please tag the relevant programming language. What is "it"? The variables j and k? The term right side of the =?
17th May 2022, 3:53 PM
Lisa
Lisa - avatar
+ 2
Maybe in your programming language ".." is not a dictionary, but in Python you did the unpacking of the keys 😉 j,k = { 'w' : 'work' , 'k' : ' kite'} dic = { 'w' : 'work' , 'k' : ' kite'} print(dic[j]) print(dic['k'])
17th May 2022, 4:13 PM
Solo
Solo - avatar
+ 2
This process in some languages is called destructuration. Ex in js: [x , y] = {x : "some" , y : "other"} // x = "some" , y = "other" The object can be called map(java) , dictionary(py) , object(js)
18th May 2022, 2:54 PM
Frank Yohan Rodríguez Pérez
Frank Yohan Rodríguez Pérez - avatar
+ 1
when i used optparse moudule parser = optparse.OptionParser() parser.add_option('-i', '--interface', dest='interface', help='Add mac address') parser.add_option('-m', '--mac', dest='new_mac') (option, arguments) = parser.parse_args() when print option it return dictinory object as i asked
17th May 2022, 4:17 PM
Subhash Devda
Subhash Devda - avatar
+ 1
i know to access the values by parser module. but, im just trying to access values like dictinory, but i'ts not possible
17th May 2022, 4:21 PM
Subhash Devda
Subhash Devda - avatar
0
Hello. This is a little vague. What language is this and are you asking about what kinda data structure it is? It looks like it a map/dictionary based on the key-value pairs. A I can't answer your second question because you did not state the language.
17th May 2022, 3:54 PM
Justice
Justice - avatar
0
this code not showing error in python. when we print(j ,k) output >> w k. but can't access values
17th May 2022, 4:00 PM
Subhash Devda
Subhash Devda - avatar
0
This is dictionary. k['w'] and k['k']
17th May 2022, 4:03 PM
Solo
Solo - avatar
0
Solo , sorry to say that it's not as dictionary
17th May 2022, 4:05 PM
Subhash Devda
Subhash Devda - avatar
0
Of course {'w': 'work', 'k': 'kite'} is a dictionary. Dictionary entries are key-value pairs: dict['key': 'value']
17th May 2022, 4:08 PM
Lisa
Lisa - avatar
0
Just to add on to Lisa comment, it might also be called a Map depending on the language.... Which you still haven't told us yet so it's hard to help.
17th May 2022, 4:10 PM
Justice
Justice - avatar
- 1
Write a program using nested loops to display the following sample out. Allow the user to enter a number and use the number to generate the output. In this the user entered 7 1 135 1357 135 1
19th May 2022, 8:50 AM
Nuhu Abdul Bashit
Nuhu Abdul Bashit - avatar