A List of Multiple Data Types

A list of multiple data types?

The easiest way to do this is to declare an interface, and have both types implement it:

public interface IMachine { … }

public class MachineLine : IMachine
{
public double X1;
public double Y1;
public double X2;
public double Y2;
public double Thickness;
}

public class MachineCircle : IMachine
{
public double CenterX;
public double CenterY;
public double Radius;
}

Then you can do this:

List<IMachine> m = new List<IMachine>();

List with multiple data type

I am guessing you need to create your deliv type as some kind of DTO with date, name and quantity fields. And also, as suggested earlier, if you want proper search by date, then Date field of your deliv type should be DateTime

Converting list with multiple data types(both string and integer) to a string in python

' '.join(map(str, sample_list))

Multiple data types in a python list

Your code is incomplete, there may be unexpected variable coverage, you can try to use the list comprehension directly.

[[datetime.datetime.strptime(i[0],'%d/%m/%Y %H:%M'), float(i[1]), float(i[2])] for i in bd]

Reading a list with multiple data types into if else statements

Make ac_on a list and append the the values for each data point. Access the the attributes of the tuples by index:

ac_on = []
for data in datas:
if data[0] > Accepted_Price or data[1] == "cloudy":
ac_on.append(False)
else:
ac_on.append(True)
return ac_on

Or as a shorter comprehension:

return [data[0] <= Accepted_Price and data[1] != "cloudy" for data in datas]


Related Topics



Leave a reply



Submit