Jump to content

Recommended Posts

Posted

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


 

Posted
1 minute ago, a_sagittarian said:

naak qn ardham kaale.

ne output em ostundi...

ela kavali rendu veyi.

Posted
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}

Posted
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)

 

  • Upvote 1
Posted
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 

Posted
37 minutes ago, a_sagittarian said:

Tried... either it prints empty dic or nothing 

Worked 

Posted
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 

Posted
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

Posted
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 5b8qx1.gif

  • Haha 2
Posted
3 minutes ago, mowa said:

 

nizam seppu college lo slippulu baga pettevadivi kada 5b8qx1.gif

Lol

Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...