[Solved] how to convert a np array of lists to a np array

I was wondering how you got the array of lists. That usually takes some trickery. In [2]: >>> a = np.array([“0,1”, “2,3”, “4,5”]) …: >>> b = np.core.defchararray.split(a, sep=’,’) …: In [4]: b Out[4]: array([list([‘0’, ‘1’]), list([‘2’, ‘3’]), list([‘4’, ‘5’])], dtype=object) Simply calling array again doesn’t change things: In [5]: np.array(b) Out[5]: array([list([‘0’, ‘1’]), list([‘2’, … Read more

[Solved] Python indentation error in if statement [closed]

Assuming there is something after the else statement, the else statement should be aligned with the if statement, not inside it. Example – if sisiter_age > brother_age: print “sisiter is older” else: Also, if you do not have (or need) anything inside the else statement, you should just remove it. 0 solved Python indentation error … Read more

[Solved] Python wondering about user input

Use a list and a while loop. data=[] for x in xrange(100): data.append(raw_input(“Your data: “)) If you don’t need to store the data that was entered, get rid of the list and process this data right in the loop. 1 solved Python wondering about user input

[Solved] how would i print all the names and scores of those users from a particular class?

Updating answer based on updated question: classdata = {} for data in schooldata: if classdata.get(data[‘class_code’]): classdata[data[‘class_code’]].append(data) else: classdata[data[‘class_code’]] = [data] print classdata To print class data (in orderly manner): for class_data in sorted(classdata): for person_data in sorted(classdata[class_data], key=lambda x: x[‘name’]): print person_data[‘class_code’], person_data[‘name’], person_data[‘score’] 15 solved how would i print all the names and scores … Read more

[Solved] Removes non-vegetarian foods from a list of foods. [closed]

def veggie_r_ip(foods, curIndex): if(curIndex >= len(foods)): return curFood = foods[curIndex] is_veggie = curFood.split(‘|’)[2] if is_veggie == “False”: foods.remove(curFood) veggie_r_ip(foods, curIndex) else: veggie_r_ip(foods, curIndex + 1) def main(): foods =[‘Spicy Vegetable Moo Shu|1|True|140’, ‘BBQ Pork|1|False|920’, ‘Chicken Breast|1|False|920’, ‘Salad|1|True|920’] veggie_r_ip(foods, 0) print foods 1 solved Removes non-vegetarian foods from a list of foods. [closed]

[Solved] python calculator with two float numbers as parameters [closed]

Hope this code may help you def add(a,b): print(a+b) def subract(a,b): print(a-b) def multipy(a,b): print(a*b) def divide(a,b): print(a/b) ch=”y” while ch==”y” or ch==”Y”: x = float(input(“first number : “)) y = float(input(“second number: “)) print(“…..MENU…….\n 1.Add\n 2.Subtract\n 3.Multiply\n 4.Divide\n”) op=int(input(“Enter your choice : “)) if op==1: add(x,y) elif op==2: subract(x,y) elif op==3: multipy(x,y) elif op==4: … Read more

[Solved] How can I make the efficent for loop in Python?

Assuming s.subjects is None or some other False value when there are no subjects, and likewise for books for s in students: for subject in s.subjects or []: for book in subject.books or []: writer.writerow(s.name, s.class, subject.name, book.name) More generally, you can write for s in students: for subject in s.subjects if <condition> else []: … Read more