

Multidimensional list Getting the position of a Python string
source link: https://www.codesd.com/item/multidimensional-list-getting-the-position-of-a-python-string.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Multidimensional list Getting the position of a Python string
I got following List
relational_scheme = [["F",["DC"]],["A",["EBD"]],["DC" , ["BAF"]],["E",["DB"]]]
Now i want to get the second List as a Set like
def returnSetOfList(relational_scheme,"F")
So that this output generates
set(["DC"])
How can i make this? an easy Index don't work.
Thanks in advance.
UPDATE
got it, was just blind Solution:
def returnSetOfList(scheme,string):
for x in scheme:
if string in x:
return set(x[1])
You can create a dictionary and then return the set()
of the value for a given key.
Example
>>> def returnSetOfList(scheme, key):
... a_dict = dict(scheme)
... return set( a_dict[key] )
...
>>> relational_scheme = [["F",["DC"]],["A",["EBD"]],["DC" , ["BAF"]],["E",["DB"]]]
>>> returnSetOfList(relational_scheme, "F")
set(['DC'])
Related Articles
How to get the ° character in a python string?
How to list all the positions of a variable in a list?
How to get the position of a Widget in a table - python
Jquery - get the position from the list
Get the position of the object in a list in Delphi?
Android: get the position of the item in a list view given its identifier:
I use the list view to search for objects, how to get the position of the selected item in the list view?
Get the position of the item in a list when dragged / dropped (ui.sortable)
How to get the position of a JavaScript regexp sub-match?
Get the position of the cursor or text in pixels for the input element
How to get the position of a recycle itemViewing when it is touched
Java Get the position of a value using an arrayist
Get the position of the split windows on a vim editor
Get the position of the selected element in action mode
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK