Iterating through list of list

This traverse generator function can be used to iterate over all the values: def traverse(o, tree_types=(list, tuple)): if isinstance(o, tree_types): for value in o: for subvalue in traverse(value, tree_types): yield subvalue else: yield o data = [(1,1,(1,1,(1,”1″))),(1,1,1),(1,),1,(1,(1,(“1”,)))] print list(traverse(data)) # prints [1, 1, 1, 1, 1, ‘1’, 1, 1, 1, 1, 1, 1, 1, ‘1’] …

Read more

Remove items of list from another lists with criteria

If you’ve actually got a List<T>, I suggest you use List<T>.RemoveAll, after constructing a set of writer IDs: HashSet<long> writerIds = new HashSet<long>(listWriters.Select(x => x.WriterID)); articleList.RemoveAll(x => writerIds.Contains(x.WriterId)); anotherArticleList.RemoveAll(x => writerIds.Contains(x.WriterId)); If you do want to use LINQ, you could use: articleList = articleList.Where(x => !writerIds.Contains(x.WriterId)) .ToList(); anotherArticleList = anotherArticleList .Where(x => !writerIds.Contains(x.WriterId)) .ToList(); Note …

Read more

List.shuffle() in Dart?

There is a shuffle method in the List class. The methods shuffles the list in place. You can call it without an argument or provide a random number generator instance: var list = [‘a’, ‘b’, ‘c’, ‘d’]; list.shuffle(); print(‘$list’); The collection package comes with a shuffle function/extension that also supports specifying a sub range to …

Read more

Unsupported operand type(s) for +: ‘int’ and ‘str’ [duplicate]

You’re trying to concatenate a string and an integer, which is incorrect. Change print(numlist.pop(2)+” has been removed”) to any of these: Explicit int to str conversion: print(str(numlist.pop(2)) + ” has been removed”) Use , instead of +: print(numlist.pop(2), “has been removed”) String formatting: print(“{} has been removed”.format(numlist.pop(2)))