11

Multidimensional list Getting the position of a Python string

 2 years ago
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

advertisements

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 can I get a ° (degree) character into a string?Put this line at the top of your source # -*- coding: utf-8 -*- If your editor uses a different encoding, substitute for utf-8 Then you can include utf-8 characters directly in the source

How to list all the positions of a variable in a list?

I have a large list of text strings. I know that some strings occur more than once in this list. The frequency with which the strings occur are in the next column. Now, let's say the text string "hello" occurs 17 times. How would I get all posit

How to get the position of a Widget in a table - python

How can you get the position number of a particular PyQt-widget in a list? I am trying to implement something like self.Reg_Labels =[] # list fot QLabel self.Reg_Fields =[] # list for QLineEdit for i in xrange(53): x = str(self.Registers(i)) self.Reg

Jquery - get the position from the list

i have the following code <ul class="MenuMainContent"> <li class="tabClass clubTab" style="display: none;"><a href="#tabs-1" class=" ">Club</a></li> <li class="tabClas

Get the position of the object in a list in Delphi?

I was wondering how you get a position of a certain object in a list that is created. Lets say it is like a graphical list where you can click on objects. Lets say you right click on a object and click "Refresh", how do I get the position of tha

Android: get the position of the item in a list view given its identifier:

getItemIdAtPosition() is a function in android used to get the id of an item in a list view given its position is there any way of doing the reverse, i.e. getting the position of an item is a list view given its id?No. You have to do it manually. Cre

I use the list view to search for objects, how to get the position of the selected item in the list view?

here i uses two Arrays to get the item id for each selected item, but i didn't get the correct position of item on list view. if i search and select an item ie:"MacBook Air" the search result shows the item as in first position and i get the pos

Get the position of the item in a list when dragged / dropped (ui.sortable)

I have a sortable list like this one: http://jqueryui.com/demos/sortable Is it possible to get the start and end position of the element in the list, when it has been moved? I'm talking about their position number, in the list. For example, if I move

How to get the position of a JavaScript regexp sub-match?

Here is a simplified version of my RegEx: re = /a(.*)b(.*)c(.*)d/; match = re.exec("axbxcxd"); As expected, this results in match[1], match[2] and match[3] being "x", but I need to get the position of the middle match number 2. In Pyth

Get the position of the cursor or text in pixels for the input element

IE allows me to create a text range in an input element, upon which I can call getBoundingClientRect() and get the position in pixels of a certain character or the cursor/caret. Is there any way of getting the position of a certain character in pixel

How to get the position of a recycle itemViewing when it is touched

I have a recyclerView inside a DrawerLayout. Each row item has an ImageView , the icon and a Textbox , the text. I use addOnItemTouchListener to detect the position of the row item when clicked by the user , in order to open a new fragment. This is m

Java Get the position of a value using an arrayist

I'm trying to get the position of the STX (0x02) from the byte array message below. If you see the message, it has 0x2 in a number of places but the only position I want is the STX one. I've been looping through it backwards using a for loop. I have

Get the position of the split windows on a vim editor

I've been trying to find out how the get the position/coordinates of a splitt window inside a vim editor window, but no luck so far. Say for example I have this layout (0,0) (2, 0) \____________/____________ | | | | Split A | Split C | (0,2)-+-------

Get the position of the selected element in action mode

When i long press any item in the list view then Contextual action bar showed. Now what i want that when i press the delete button after selecting items then the selected items get deleted but I am unable to get the position of selected items. My cod

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK