back soft

مطالب مرتبط با «python list of objects» در back soft | نویسنده: استخدام کار

How restrict creation of objects of one class to instances of another in Python?

Vote count: 0 I have encountered a conundrum. I think I should know how to solve this — I even wrote a Python book — but I can't figure it out. It seems like what I am struggling with should be addressed by a design patte that is a variation on the factory theme, but I can't recall one. (At the end of this writeup I suggest a technical solution, but it seems an implausible one.) I hope you find this discussion interesting in its own right, but I look forward to hearing some suggestions for solut...

ادامه مطلب

How to iterate through a list in Python without a loop?

Vote count: 0 Suppose I want to print all the elements between index 2 and 8 of the list, how do I implement this without using a for, or while loop? asked 13 secs agoFalcon2908 Let's block ads!...

ادامه مطلب

I am trying to plot a list of imaginary numbers using sympy but the below error is thrown.

Vote count: 0 Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jul 2 2016, 17:42:40) [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2 Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out: http://continuum.io/thanks and https://anaconda.org >>> from sympy import symbols >>> from sympy.plotting import plot >>> L = [2+2j, 3+2j, 1.75+1j, 2+1j, 2.25+1j, 2.5+1j, 2.75+1j, 3.25+1j] >>> plot(L) Traceback (most recent c...

ادامه مطلب

Python - Pass a range of float (without step) as an argument of a function

Vote count: 0 I created a function and I would like to be able to call it with a set of keyworded-parameters that I called '**criterias': def actionBasedOnParameters(**criterias): # my code Inside this set of parameters one of them will be called 'SumInc' and I would like to pass on a range to it. A range that will be of the form of [1:15] or [1:] or [:15]. Something that will essentially let me check whether a variable in my code is greater than a certain boundary or lower than another boundary...

ادامه مطلب

How to find the index of next matching element in list using LINQ

Vote count: 0 i have a list say : List list = new List(){"Oracle","SQL Server","Java","Oracle","Python"}; Now i'm trying to get index of the second "Oracle" from the list using LINQ: var indexFirefox = list.FindIndex(a => a.Text == "Oracle"); But this will give you only the first instance that is index 0. I want index as 4 in my result. Will using Skip help or there is a more simplistic way of getting the index. The example above is just a demo, i have a list with over 300 values. asked 31 secs ...

ادامه مطلب

Python list of lists filled with duplicate rows after writing each entry

Vote count: 0 I am iterating over each entry of a list of lists and filling it with some unique number but the final list of lists contains identical rows. Here's a MWE: x = [1,2,3,4] y = [3,6,9,12] Here I set up a list of lists filled with zeros. m = [[0]*len(x)]*len(y) And I print it to make sure it looks right. [print(i) for i in m] Now I iterate through each row and again through each item in the row and put the result of some calculation in each spot. for i,ii in enumerate(y): for j,jj in e...

ادامه مطلب

For two lists, l1 and l2, how to check that for all e1 ∈ l1, ∃p(e1,e2) where e2 is some element in l2, efficiently in python?

Vote count: 0 Ok, not sure if that was the best title, but I have two python lists. L1 and L2 which both have elements of type T and do not have the same length. I have a function p(T,T) which is a predicate checking a property about two elements of type T. I would like to check that for all elements e in L1, p(e,e') holds, where e' is SOME element in L2. so basically for each element in L1 I go over the second list, and check if the predicate holds for any of the elements. But I also want to ch...

ادامه مطلب

wxPython: ListBox not selectable/clickable when used with ComboCtrl

Vote count: 0 I am trying to couple wx.ListBox with wx.combo.Comboctrl. A sample code is below. For some reason, the items in the ListBox are not clickable/selectable. I wonder how I can make it work. Thanks! import wx, wx.combo class MainFrame(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, title="", size=(300, 100)) gbs = wx.GridBagSizer() ComboCtrlBox = wx.combo.ComboCtrl(self) ComboCtrlPopup = ListBoxComboPopup() ComboCtrlBox.SetPopupControl(ComboCtrlPopup) ComboCtrlPo...

ادامه مطلب

Android - Passing an ArrayList of Custom Objects to Another Activity

Vote count: 0 So, I've been struggling on this for a while and have searched on here for hours without finding anything that really helped. I have a custom class Streak. When the user creates a new Streak in my Main Activity, I want for that streak to be added to a list of total streaks, which I would then access from an AllStreaks activity. I have tried using Gson, but received errors. What I have below is working for the time being, but since my global variable has to be declared as new. I don...

ادامه مطلب

Why the mmap of Python is much slower than C++'s?

Vote count: 0 C++ code: #include #include #include #include #include using namespace std; #define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) int main() { timeval tv1, tv2, tv3, tve; gettimeofday(&tv1, 0); int size = 0x1000000; int fd = open("data", O_RDWR | O_CREAT | O_TRUNC, FILE_MODE); ftruncate(fd, size); char *data = (char *) mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); for(int i = 0; i < size; i++) { data[i] = 'S'; } munmap(data, size); close(fd); gettimeofday(&tv2, 0); ...

ادامه مطلب

How to get the Average of a specific category via Python

Vote count: 0 I was wondering how I could calculate the average of a specific category via Python? I have a csv file called demo.csv import pandas as pd import numpy as np #loading the data into data frame X = pd.read_csv('demo.csv') the two columns of interest are the "Category" and "Totals" column: Category Totals estimates 2 2777 0.43 4 1003 0.26 4 3473 0.65 4 2638 0.17 1 2855 0.74 0 2196 0.13 0 2630 0.91 2 2714 0.39 3 2472 0.51 0 1090 0.12 I'm interested in finding the average for the Totals...

ادامه مطلب

Shape of numpy array comparison with empty list

Vote count: 0 I have some problems understanding how python/numpy is casting array shapes when comparing to an empty list - which as far as I understand - is an implicit (element wise) comparison with False. In the following example the shape decreases by one in the last dimension, if it is not greater than 1. z = N.zeros((2,2,1)) z == [] >> array([], shape=(2, 2, 0), dtype=bool) z2 = N.zeros((2,2,2)) z2 ==[] >> False If, however, I compare with False directly, I get the expected output. z = N.z...

ادامه مطلب

ec2-describe-images how to list the creation date of ami for all the AMI's created by specific owner

Vote count: 0 I am using AWS CLI to get the list of AMI's created by specific owner however I want to get the creation date of the AMI along with the size of the AMI The command I am using is below. ec2-describe-images --filter "is-public=false" --filter "architecture=x86_64" --filter "owner-id=xxxxxxx" Please guide me. asked 23 secs agoNarendra522 Let's block ads!...

ادامه مطلب

Python - Having user sort list smallest to biggest

Vote count: 0 So I'm making a code where it asks the user to to swap two places on the list until the list is from smallest to biggest. So it should look like this: Hello: Your current list is [6, 7, 8, 2 , 9, 10, 12, 15, 16, 17] Please pick your first location -> 4 Please pick your second location -> 2 Your new list is [6, 2, 8, 7 , 9, 10, 12, 15, 16, 17] I've gotten to this part but I am currently unable to figure out how to get the USER to do the sorting and not the code. Your list is not sor...

ادامه مطلب

Python combine 2 lists of strings for CSV

Vote count: 0 I have two lists that I want to combine for csv output. alist = ['a', 'b', 'c'] blist = ['d', 'e', 'f'] However, I want the output for the csv to format like this: clist = ['a', 'b', 'c', 'd' 'e' 'f'] such that the last entry extended of the list contains the list of "blist", but will not be comma separated. Unfortunately, what I have been trying instead gives me: clist = ['a', 'b', 'c', 'def'] asked 1 min agoArca Let's block ads!...

ادامه مطلب

Need an excel macro that which can select data from drop down list and copy the contents of the entire sheet into a new work book

Vote count: 0 I have a dashboard which contains many formulas that change depending on the value on the drop down list. Is there any macro which can run a loop for all the values in the drop down list, copy the contents of the entire sheet and paste it into a new workbook? asked 31 secs agoadithya viswanathan Let's block ads!...

ادامه مطلب

Generate different totals of an image using a checkboxlist and user input

Vote count: 0 I have a barcode generator that takes information stored in a database and generates a barcode from a databound checkboxlist selection. There are different check boxes, the user checks the boxes of the items they want and enter a universal total. protected void btnGenerate_Click(object sender, EventArgs e) { int n; int i = Int32.Parse(BatchNumText.Text); for (n = 1; n...

ادامه مطلب

In C#, Rotate a List to The Right by the specified numbers of places without using LINQ?

Vote count: 0 I am trying to rotate a List of items to the right by the specified numbers of places without using LINQ, how am I able to do this? I think I am not understanding how to approach/solve this problem in particular. Here's what I have tried so far. public void Test(List items, int places) { items.RemoveAt(places); items.Add(places); } asked 1 min agoZerox Let's block ads!...

ادامه مطلب

How do I create an array of objects, and give them different values in the constructor

Vote count: 0 First time asking a question on Stack Overflow, I'll try my best. In C++11, can I declare an Array of Objects, and then give them different values in initialization? My Code looks like this. I thought I could initialize them like I would a struct. #include #include #include "personType.h" int main(){ personType people[3]{{ "Jacob", "Hicks" }, { "Moria", "Brown" }, { "Marty", "Robinson" }}; } The Constructor in question looks like this personType(std::string first = "", std::string ...

ادامه مطلب

How to create a list of record to mongoDb using expressJs

Vote count: 0 I want to create a array of object to mongoDb using expressJs (restful API ) . I have a array like this : [ { name: 'java', _id: 578c81ea7d5940501419e819, articles: [] }, { name: 'C#', _id: 578c81ea7d5940501419e81a, articles: [] }, { name: 'C++', _id: 578c81ea7d5940501419e81b, articles: [] }, { name: 'cloud', _id: 578c81ea7d5940501419e81c, articles: [] } ] How can I insert this array to mongoDB by only one function ? thanks for any help . asked just nowTrần Dương Let's block ads!...

ادامه مطلب