1. Add a value to each element in a list:
Degrees_zero = [F + 459.67 for F in Fahrenheit_degrees]
2. Assign the index of a list into the list:
Survey_responses = ["None", "some", "a lot", "none", "a few", "none", "none"]
Survey_scale = ["None", "a few", "some", "a lot"]
Survey_numbers = [Survey_scale.index (response) for response in Survey_responses]
average_smoking = SUM (smoke_dic)/len (smoke_dic)
3. Categorize Scales:here We need to filter gender list into categorizes and find the Corresponse saving.
gender = ["Male", "female", "female", "male", "male", "female"]
Savings = [1200, 5000, 3400, 2400, 2800, 4100]
Solutions one////////////////////////////////////////
Male_saving_list = []
For I in range (Len (gender)):
If gender[i] = = "Male":
Male_saving_list.append (Savings[i])
male_savings = SUM (male_savings_list)/len (male_savings_list)
Solutions two////////////////////////////////////////
Female_saving_list = [Savings[i] for I in range (Len (gender)) if gender[i] = = "female"] # Here we use square bracket to Replace append function. Savings[i] is the value of we want, if conditions has to follow the as loop like solution one.
female_savings = SUM (female_saving_list)/len (female_saving_list)
4.
Statistics and Linear Algebra 1