Add item to a List<Tuple> inside another list

Add item to a List<Tuple> inside another list

By : Muhammed Ahtisham Ir
Date : November 19 2020, 03:01 PM
around this issue I think I figured out your problem. In general it is difficult to modify what you are iterating through with foreach.
This solution will iterate through every month between the min and the max. It will then iterate through every list. If the list doesn't have that month then it is inserted into the list.
code :
for (int i = 0; minDate <= maxDate; i++)
    for (int list = 0; list < myList.Count; list++)
        if (myList[list].Count <= i || myList[list][i].Item1 != minDate)
            myList[list].Insert(i, Tuple.Create(minDate, 0));

    minDate = minDate.AddMonths(1);
for (var i = minDate; i <= maxDate; i = i.AddMonths(1))
    for (int list = 0; list < myList.Count; list++)
        if (!myList[list].Any(tuple => tuple.Item1 == i))
            myList[list].Add(Tuple.Create(i, 0));

myList.ForEach(item => item.Sort((x, y) => x.Item1.CompareTo(y.Item1)));
var dates = myList.SelectMany(list => list).Select(item => item.Item1);
minDate = dates.Min();
maxDate = dates.Max();

Share : facebook icon twitter icon
Fill Tuple item as a List inside a Dictionary

Fill Tuple item as a List inside a Dictionary

By : Osaid Ahmad
Date : March 29 2020, 07:55 AM
this one helps. I have a Dictionary in my code defined in a method as: , You need to initialize the dictionary:
code :
public Dictionary<int, AuthorData> GetAuthorData(int startYear, int endYear)
    var authorData = new Dictionary<int, AuthorData>();

    foreach (var paper in Papers.Where(p => p.Year >= startYear && p.Year <= endYear))
                        new AuthorData()
                            CoAuthors = paper.CoAuthors,
                            PaperCategory = paper.PaperCategory,
                            VenueID = paper.VenueID,
                            Year = paper.Year

    return authorData;

class AuthorData
       public List<int> CoAuthors { set; get; }
       public int PaperCategory { set; get; }
       public int VenueID { set; get; }
       public int Year { set; get; }
Dictionary<int, Author.AuthorData> tauthorData = eAuthor.GetAuthorData(year, year + 1);
foreach (var kvauthor in tauthorData)
    foreach (var author in kvauthor.Value.CoAuthors)
        tw.WriteLine("PaperID: {0}, CoAuthors: {1}, PaperCategory: {2}, Venue: {3}, Year: {4}",
        kvauthor.Key, author, kvauthor.Value.PaperCategory,
        kvauthor.Value.VenueID, kvauthor.Value.Year);
why is the type of a tuple a list when only one list is present inside the tuple?

why is the type of a tuple a list when only one list is present inside the tuple?

By : user5697646
Date : March 29 2020, 07:55 AM
it should still fix some issue The proper syntax for creating a tuple with only one item is to follow the item with a comma:
code :
List to tuple counting values repeated and the list inside the tuple - Haskell

List to tuple counting values repeated and the list inside the tuple - Haskell

By : chirag
Date : March 29 2020, 07:55 AM
I hope this helps you . Usually it helps to think of functions like in mathematics you think about inductive definitions. For example the first line of your function can read like:
"The ex3 of an empty list, and any element is a tuple containing the empty list and zero"
code :
ex3 [] _ = ([], 0)
ex3 [] _ = ([], 0)
ex3 (x:xs) z | x /= z = (x:t, n)
             | otherwise = ...
    where (t, n) = ex3 xs z
ex3 :: (Eq a, Num n) => [a] -> a -> ([a], n)
ex3 [] _ = ([], 0)
ex3 (x:xs) z | x /= z = (x:t, n)
             | otherwise = (t, n+1)
    where (t, n) = ex3 xs z
Prelude> ex3 [2,3,4,2,2] 2
Prelude> ex3 [1,1,1,1] 1
Prelude> ex3 [1,2,3,4] 5
How to access an item in a tuple when the tuple is inside a list?

How to access an item in a tuple when the tuple is inside a list?

By : Parker
Date : March 29 2020, 07:55 AM
This might help you Obviously PPAttachment is not a tuple, nor is it apparently a namedtuple. To get the third element, you'll probably want to access the value by name:
List of tuples [{id, [<List>]}, {id2, [<List>]} ] where ids are the second item of the tuple of the original

List of tuples [{id, [<List>]}, {id2, [<List>]} ] where ids are the second item of the tuple of the original

By : Keenan Holder
Date : March 29 2020, 07:55 AM
Does that help Erlang newbie here. I created a dict with the second members of the tuples as keys and lists of corresponding tuples as values, then used dict:fold to transform it into the expected output format.
code :
-export([test/0, transform/1]).

transform([H|T]) ->
    transform([H|T], dict:new()).

transform([], D) ->
      dict:fold(fun (Key, Tuples, Acc) ->
transform([Tuple={_S1,S2,_S3}|T], D) ->
    transform(T, dict:append_list(S2, [Tuple], D)).

test() ->
    case Output of
        ]     -> ok;
        _Else -> error
Related Posts Related Posts :
  • Headless Firefox in Selenium C#
  • How do I start a .exe with a json string as parameter correctly?
  • StreamContent not loaded to the end
  • HAP parses formatting in HTML documents
  • repeat and count a loop in an unordered sequence in C#
  • Redundant Casting in Visual studio
  • Lost references in Visual Studio 2017 solution
  • Is there a way to add two numbers using a private constructor in C#
  • Is it possible to execute multiple SSH commands from a single login session with SSH.NET?
  • How can I get NHibernate to map to a Tuple or Class?
  • MVC 5 C# Window Authentication pop up when I navigate to a certain area
  • Mongo C# driver toJson() DateTime
  • Coprime integers
  • What is the purpose with files ending with *CS.cs in Xamarin Forms projects?
  • MVC5 / Entity | Update/Create Complex Model
  • How to return auto increment ID from SQL using Petapoco ORM in .NET MVC
  • Create new web app offline c# using Visual Studio
  • How many times is ordered the IEnumerable in this case?
  • C# error when update database 2008 to sql 2016
  • How to insert string in multiple continuous pattern in windows c#
  • How to send temp data from Partial View to its parent View
  • C# encapsulation when getting updates from asynchronous method
  • Asp net core Content Security Policy implementation
  • @Html.DropDownList() Placeholder as Disable and Selected
  • Set AM/PM in Material Time Picker WPF
  • Ninject passing reference in constructor
  • C# Entity Framework text SQL query wrapper
  • Core 2.0 MVC - AD Group Authorization for logging
  • Decentralized NLog Target per Http request
  • How to use x:Object and when?
  • Displays file icons in asp.net on GridView
  • How do I avoid two (or more) threads that work on a table at the same time to not work on same row?
  • Add xml attribute for property in DB First
  • How do i execute 2 sql queries by clicking a button [C#]
  • convert jsonstring to objects c#
  • How do request a correct access token in ASP.NET Core for Azure AD to access Microsoft Graph
  • How to run a .NET Core console application on Linux
  • UI not updating for bound element
  • C# Odata v4 open type raw values
  • DocumentFormat.OpenXml Modify Creator Propery of Document
  • How to SetBasePath in ConfigurationBuilder in Core 2.0
  • ASP MVC5 public readonly variable changes value when it should not
  • How to conditionally select item from hashset with queryable linq?
  • Progress Bar C# not showing the real progress
  • Correct logic to reconnect in SignalR with HubConnection
  • ComboBox with two or more sections
  • .NET listbox to SQLite DB
  • C# Ninject binding from Dictionary<Type, Type>
  • asp.net mvc -view displaying real-time progress status
  • Getting reference to dependent in service with generic type
  • Implementing EqualityCompare vs overriding GetHashCode and Equals
  • C# Linq Find all indexes of item in List<int> within another List<int>
  • XML image how to display at data grid columns in c#.net
  • How to override Equals and GetHash of HashSet
  • Creating Windows authentication and SQL Server authentication in login form
  • How to interop with Azure Service Bus topics created by MassTransit using Rebus?
  • MVC 5 Google Calendar Integration
  • C# - Use parallel arrays to calculate cost of a phone call in GUI
  • Use a int in entire code
  • How to display newly added element at the top of StackPanel in WPF?
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org