- 2
j,k = { 'w' : 'work' , 'k' : ' kite'}
Please tell what type of object it is, and how can access its values
14 Antworten
+ 4
Nuhu Abdul Bashit ,
please do not post a new question / thread inside an exising thread of a other user.
+ 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'
+ 2
Please tag the relevant programming language.
What is "it"? The variables j and k? The term right side of the =?
+ 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'])
+ 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)
+ 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
+ 1
i know to access the values by parser module.
but, im just trying to access values like dictinory, but i'ts not possible
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.
0
this code not showing error in python.
when we print(j ,k) output >> w k. but can't access values
0
This is dictionary.
k['w'] and k['k']
0
Solo , sorry to say that it's not as dictionary
0
Of course {'w': 'work', 'k': 'kite'} is a dictionary.
Dictionary entries are key-value pairs:
dict['key': 'value']
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.
- 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