Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
return dict in tuple
#1
i return something like this from function:
def f():
    d = dict()
    # fill dict
    d["s"]
    return (1, d)
then:
ret = f()
d = ret[1]
print (d["s"])
on print line i get "sequence is not an int, slice or ... __index__"

please help!
Reply
#2
Is this really the code you run to get the error you mentioned?
On line 4 in f() you do not assign a value to the key "s", which gives an error when I run your code.
Reply
#3
(Feb-26-2018, 08:01 AM)j.crater Wrote: Is this really the code you run to get the error you mentioned? On line 4 in f() you do not assign a value to the key "s", which gives an error when I run your code.
sorry, i do assign a value.
Reply
#4
If I modify the code so that it assigns a value, it works for me. You may want to be more specific about the code and error you get.
Reply
#5
oh. this is weird. now it works for me too. i haven't changed anything...
Reply
#6
(Feb-26-2018, 10:10 AM)bb8 Wrote: oh. this is weird. now it works for me too. i haven't changed anything...
That is a miracle...
Reply
#7
(Feb-26-2018, 12:47 PM)buran Wrote:
(Feb-26-2018, 10:10 AM)bb8 Wrote: oh. this is weird. now it works for me too. i haven't changed anything...
That is a miracle...
people usually say this about c++ but in thia case:
that is python...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  search in dict inside tuple steg 1 685 Mar-29-2023, 01:15 PM
Last Post: rob101
  Return both key and value by calling only dict value mapypy 3 2,181 Feb-06-2021, 10:50 AM
Last Post: Serafim
  What type of *data* is the name of a list/tuple/dict, etc? alloydog 9 4,367 Jan-30-2021, 07:11 AM
Last Post: alloydog
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 2,805 Nov-04-2020, 11:26 AM
Last Post: Aggam
  Sort a dict in dict cherry_cherry 4 73,148 Apr-08-2020, 12:25 PM
Last Post: perfringo
  How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? SukhmeetSingh 5 3,187 May-21-2019, 11:39 AM
Last Post: avorane
  Iterate a tuple with dict inside anna 2 2,411 Feb-13-2019, 03:44 PM
Last Post: anna

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020