[3,4,5]
and i want to assign these values to variables, but i want to assign the number with the middle VALUE, how do i go about doing that?
8 2717
that didn't really help :/... if i already assigned 2 of the numbers can i assign it by the only unassigned element in the list?
You should at least read it, before asking someone else to do it for you. Verbatim copy:
l = ['a', 'b', 1, 'a cat']
and access it with indices, exactly as you did with character strings:
>>> l[1]
'b'
yes yes, i know that but the problem was that the list is user inputed and it is subject to change so that wont work and besides i read it all, it doesn't even cover all the function possibilities of a list.
Do you mean the median of the list? Eg if your list were [5,3,4] would you want to assign a variable to 4, or to 3? I think the question is ambiguous. Perhaps you can try to be more clear about exactly what it is that you want.
Is the issue that the list might have a variable number of elements? Or that you want to assign to the median element? Or that you want to assign to an element that has not yet been used for something?
Help us to help you!
yes,It was a question about returning the median of a list of only 3 elements that the user enters, heres a snippet of my code if it helps, i need B to represent the median of the list.
[side_1=input('Enter side one: ')
side_2=input('Enter side two: ')
side_3=input('Enter side three: ')
values=[side_1,side_2,side_3]
A=min(values)
B=
C=max(values)]
bvdet 2,851
Expert Mod 2GB
The median of any list is the middle value in a sorted list. - >>> values = [3,8,2,9,6]
-
>>> sorted(values)
-
[2, 3, 6, 8, 9]
-
>>> sorted(values)[len(values)/2]
-
6
-
>>>
It's a bit more complicated when the list contains an even number of elements.
bvdet's method should work fine for you, Justin. Although, if you're using python 3, if I recall it won't do the floor division, so instead use: - B=sorted(values)[(len(values)-1)/2]
or, since you know the length already, just use: Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brett L. Moore |
last post by:
Hi,
I have had trouble determining whether the STL list.size() operation
is O(1) or O(n). I know the list is a doubly-linked list, so if the
size() operation begins at the head, then counts to...
|
by: Steven Bethard |
last post by:
George Sakkis wrote:
> "Steven Bethard" <steven.bethard@gmail.com> wrote:
>> Dict comprehensions were recently rejected:
>> http://www.python.org/peps/pep-0274.html
>> The reason, of course,...
|
by: Mukesh |
last post by:
Hi all,
First of all thank u,
It is possible to get a list of ip addresses in a len if yes then how
and what are the different libs for diffrent os like linux windows.
|
by: c_kubie |
last post by:
I am not very Access03 efficient.
I have managed to create a listbox within a form. I would like to have
the listbox selection update the form with the appropriate information
from that row.
...
|
by: Ron |
last post by:
Hi,
I need to prefome a sync process on two Lists
Lets say i have two Lists of type string.
And each list can be dimensioned differently, but will eventually
contain the same amount of elements...
|
by: Weste |
last post by:
I have 2 list boxes bound to a database. The 1st list box displays services
ordered by the customer. I want the 2nd list box to display services not yet
ordered by the customer.
For example. My...
|
by: zfareed |
last post by:
I have a program that creates a linked list and is required to count
the number of elements in the list. This is what I have thus far.
#include <iostream>
using namespace std;
struct listrec
{...
|
by: J2EE Convert |
last post by:
Hello,
Sorry if this has already been beaten to death. However, I was not
able to find the answer in my searches. Is there any performance trade
off between creating and using a generic list of...
|
by: parez |
last post by:
Hi,
I am trying to serialize List<List<string>.
With the following code
public List<List<string>DataRows { get; set; }
|
by: lpinho |
last post by:
Hi all,
I have a class (named for the example myObject) that can be of
several types (int, string, float, etc), instead of using a object to
define it's type I used a generic.
public class...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |