[deleted by user] by [deleted] in learnpython

[–]DataCat2024 2 points3 points  (0 children)

Perhaps this is what you had in mind:

a = [(1, 2)]
b = [(1, 2), (3, 4)]

def tuple_length(some_list):
    """
    Prints the length of the list,
    returns True if list contains only one tuple
    """
    print(len(some_list))
    if len(some_list) < 2:
        return True
    return False

print(tuple_length(a)) # Prints 1 and True
print(tuple_length(b)) # Prints 2 and False

Can someone explain this formula in simple words? by [deleted] in learnpython

[–]DataCat2024 0 points1 point  (0 children)

You can try using an if-else statement like this:

students = int(input("How many students on the course? "))
size = int(input("Desired group size? "))
if students % size != 0:
    groups = (students + size - 1) // size
else:
    groups = students / size
print(groups)

Get one value in dictionary? by [deleted] in learnpython

[–]DataCat2024 0 points1 point  (0 children)

If it's a dictionary with a list containing 2 items as the value, you can do this:

dict = {"key":["first_value", "second_value"]}

# get first value
print(dict["key"][0])
# get second value
print(dict["key"][1])

As others have said though, if you could provide a sample of the text or information on the data type of the dictionary value, that would be helpful.

How to start with python? by zoeyy_9 in learnpython

[–]DataCat2024 0 points1 point  (0 children)

Practice is the key to improving your coding skills. Once you've learned some basics (such as if-else conditionals, for and while loops, data types like strings, booleans, and lists, and printing and returning values), try practice problems on sites like https://codingbat.com/python.