# Verstion of List.MatchWithKeyValues in DesignScript

**URL:** <https://forum.dynamobim.com/t/verstion-of-list-matchwithkeyvalues-in-designscript/5780>\
**Category:** Packages\
**Tags:** clockwork\
**Created:** [August 22, 2016, 11:40pm UTC](https://forum.dynamobim.com/t/verstion-of-list-matchwithkeyvalues-in-designscript/5780 "2016-08-22T23:40:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Greg\_McDowell](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/greg_mcdowell/32/21011_2.png) [@Greg\_McDowell](https://forum.dynamobim.com/u/Greg_McDowell)\
**Post date:** [August 22, 2016, 11:40pm UTC](https://forum.dynamobim.com/t/verstion-of-list-matchwithkeyvalues-in-designscript/5780/1 "2016-08-22T23:40:31Z")

</div>

I’ve got two corresponding lists. One list of lines/curves and another of strings. The lines list eventually gets reordered in my graph and I need to get the strings list in the same order.

With something like text as my original and key list I can use List.MatchWithKeyValues to generate a set of values (I am using a range matching the index of the original list) that I can use in a List.GetItemAtIndex on the strings list to reorder them. The problem is the MatchWithKeyValues doesn’t work with lines.

DesignScript has an IsAlmostEqualTo function (?) that works but I don’t see a way I understand to do this in Python so… I’m wondering if we can translate the MatchWithKeyValues to DesignScript.

This just returns null;

```
def KeyValue(items:var[]..[],keys:var[]..[],values:var[]..[])
{
return = [Imperative]
{
lst:var[];
for (i in items)
	c = 0;
	for (k in keys)
		{
		if (i.IsAlmostEqualTo(k) && true)
			lst = values[c];
			return=lst;
                c = c + 1;
		}
}
};

```

You might be able to tell… I don’t really know what I’m doing yet. I just sort of hack away until I get something that works!

Of course, if there’s another solution I’m all ears! Thanks.

---

<div class="post-metadata">

**Author:** ![Yu\_Ke](https://avatars.discourse-cdn.com/v4/letter/y/7c8e57/32.png) [@Yu\_Ke](https://forum.dynamobim.com/u/Yu_Ke)\
**Post date:** [August 23, 2016, 3:07am UTC](https://forum.dynamobim.com/t/verstion-of-list-matchwithkeyvalues-in-designscript/5780/2 "2016-08-23T03:07:31Z")

</div>

It depends on how you sort the original list 🙂

Let’s start from naive way of getting all indices in original list and reorder string list. Firstly you could write a helper function like this:

```
def getIndex(list:Geometry[], element:Geometry)
{
    return = [Imperative]
    {
        count = List.Count(list);
        for (i in 0..count)
        {
           if (element.IsAlmostEqualTo(list[i]))
           {
               return = i;
           }
        }
        return = -1;
    }
}

```

And then use this function to get indices of geometries in original list, and get reordered strings:

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/a/a454f0d52497abc4dbe0b447899c3897019cccb8.png)

The other way is to associate the geometry list with string list. That is, you can create a list whose each item is _a list_ which contains two items: `{geometry, string}`. For example:

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/7/795a3499f8b73a4ca7e3600b450d21530adcc123.png)

Now we can sort this list based on the first item of each sublist. Say, we try to sort based on the Y coordinates by using `List.SortByKey`:

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/2X/f/fa01066dffeaa56cf1f4d6933e56771f9b59ada9.png)

Through this way we can associative two lists together and dont need to reorder string list.
