C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# Order a list of elements with another list of doubles

By : Wawalisa
Date : January 12 2021, 07:00 PM
wish helps you I'm working with the Revit API and I have two lists, one of Elements and other of Doubles, these doubles are extracted from the pointXYZ where these elements are positioned on the Z axis. I need to order the elements list using the double list, and need to work with other lists like curves, points. , You can use Dictionary That way
code :
``````Dictionary<Elements, double> dic = new Dictionary<Elements, double>();
for (int i = 0; i < listDouble.Count; i++)
{
}
var newListElements=dic.OrderBy(x => x.Value).Select(x=>x.Key).ToList();
``````

Share :

## Python script to remove unique elements from a list and print the list with repeated elements in proper order

By : Mathinator06
Date : March 29 2020, 07:55 AM
the classical if x in dict1.keys() => if x in dict1 to be sure to use the dictionary check instead of linear no list comprehension: append in a loop, not as performant. O(n^2) complexity because of the double loop
code :
``````from collections import Counter

list1 = [1,2,1,1,3,5,3,4,3,1,6,7,8,5]

c = Counter(list1)
new_list1 = [k for k in list1 if c[k]>1]

print(new_list1)
``````
``````[1, 1, 1, 3, 5, 3, 3, 1, 5]
``````

## How to create new list from list of list where elements are in new list are in alternative order?

By : wiem chaaben
Date : March 29 2020, 07:55 AM
wish helps you Use the SelectMany and Select overloads that receive the item's index. That will be used to apply the desired ordering. The use of the SelectMany is to flatten the nested collections level. Last, apply Take to retrieve only the desired number of items:
code :
``````var result = l.SelectMany((nested, index) =>
nested.Select((item, nestedIndex) => (index, nestedIndex, item)))
.OrderBy(i => i.nestedIndex)
.ThenBy(i => i.index)
.Select(i => i.item)
.Take(10);
``````
``````var result = (from c in l.Select((nestedCollection, index) => (nestedCollection, index))
from i in c.nestedCollection.Select((item, index) => (item, index))
orderby i.index, c.index
select i.item).Take(10);
``````
``````var result = l.SelectMany((nested, index) =>
nested.Select((item, nestedIndex) => new {index, nestedIndex, item}))
.OrderBy(i => i.nestedIndex)
.ThenBy(i => i.index)
.Select(i => i.item)
.Take(10);
``````

## filter out list elements that match another list and preserve the original list order

By : user1981721
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Lets say i have following list , You need to check if master in period:
code :
``````master_list = ['Q1', 'Q2', 'Q3', 'Q4', 'S1', 'S2', 'FY']
periods = ['2017 Q1', 'TEST2', '2018 Q4', '2017 Q2', '2019Q3', '2017 Q3', '2017 Q4', '2017 FY', 'TEST']
a = [period for period in periods for master in master_list if master in period]

print(a)
``````
``````['2017 Q1', '2018 Q4', '2017 Q2', '2019Q3', '2017 Q3', '2017 Q4', '2017 FY']
``````

## How to duplicate such that it doubles the size of the list by repeating them in order at the end of the original list

By : user2164786
Date : March 29 2020, 07:55 AM
To fix the issue you can do You're modifying the list while you're navigating over it. So your loop will keep going further than you expect. i.e. at the start of the loop you have head as the first in the list and temp as the last. You then add a next to temp, so when head gets to be temp (which was the end of the list) it will have a next.
Also as you're adding temp.getNext() as the next in the new ListNode the order becomes reversed.
code :
``````public void duplicate(ListNode front) {
ListNode temp = front;
int size = 0;
while (temp != null && temp.getNext() != null) {
temp = temp.getNext();
size++;
}

while (head != null && size-- >= 0) {