a_sagittarian Posted May 27, 2021 Report Posted May 27, 2021 how to return output as dictionary for example, input ila istunte output display avtundi as below. But I want to return output as dictionary. How is it possible. Or: I want to substitute y values with x as reference in a different string. How ? Input: for (x, y in .....): print (x,y) output: x0 y0 x1 y1 x2 y2 Quote
Spartan Posted May 27, 2021 Report Posted May 27, 2021 1 minute ago, a_sagittarian said: @Spartan naak qn ardham kaale. ne output em ostundi... ela kavali rendu veyi. Quote
a_sagittarian Posted May 27, 2021 Author Report Posted May 27, 2021 5 minutes ago, Spartan said: naak qn ardham kaale. ne output em ostundi... ela kavali rendu veyi. Current_output: 0 abc 1 def 2 klm Desired_ouput: {0:abc, 1:def, 2:klm} Quote
Spartan Posted May 27, 2021 Report Posted May 27, 2021 play aroud with this.. https://www.w3schools.com/python/python_json.asp 1 Quote
jajjanaka_jandri Posted May 27, 2021 Report Posted May 27, 2021 18 minutes ago, a_sagittarian said: Current_output: 0 abc 1 def 2 klm Desired_ouput: {0:abc, 1:def, 2:klm} ok, create a dummy dictionary and start assigning values. dic = {} dic[0] = abc dic[1] = def and so on . you can loop that for x, y in .. dic[x] = y print(dic) 1 Quote
a_sagittarian Posted May 27, 2021 Author Report Posted May 27, 2021 43 minutes ago, jajjanaka_jandri said: ok, create a dummy dictionary and start assigning values. dic = {} dic[0] = abc dic[1] = def and so on . you can loop that for x, y in .. dic[x] = y print(dic) Tried... either it prints empty dic or nothing Quote
a_sagittarian Posted May 28, 2021 Author Report Posted May 28, 2021 37 minutes ago, a_sagittarian said: Tried... either it prints empty dic or nothing Worked Quote
a_sagittarian Posted May 28, 2021 Author Report Posted May 28, 2021 2 hours ago, Spartan said: play aroud with this.. https://www.w3schools.com/python/python_json.asp To do this.. first output malli json lo ki convert cheyali. But I used this in later steps. Thank you! Quote
jajjanaka_jandri Posted May 28, 2021 Report Posted May 28, 2021 2 hours ago, a_sagittarian said: Worked Cool, but the problem with that is, if there is another key of same type the value gets replaced Quote
a_sagittarian Posted May 28, 2021 Author Report Posted May 28, 2021 10 minutes ago, jajjanaka_jandri said: Cool, but the problem with that is, if there is another key of same type the value gets replaced Ikkada aa problem ledu Quote
mowa Posted May 28, 2021 Report Posted May 28, 2021 3 hours ago, a_sagittarian said: Tried... either it prints empty dic or nothing 2 hours ago, a_sagittarian said: Worked nizam seppu college lo slippulu baga pettevadivi kada 2 Quote
a_sagittarian Posted May 28, 2021 Author Report Posted May 28, 2021 3 minutes ago, mowa said: nizam seppu college lo slippulu baga pettevadivi kada Lol Quote
kathiramdasu Posted May 28, 2021 Report Posted May 28, 2021 list1 = [0,1,2,3,4] list2 = ['Hello', "How", "are", "you", "?"] mydict = {} for x, y in zip(list1, list2): mydict[x] = y print mydict Output {0: 'Hello', 1: 'How', 2: 'are', 3: 'you', 4: '?'} I dont know where you are picking x and y from , I assume its a list. This is working for me Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.