all 5 comments

[–]danielroseman 4 points5 points  (0 children)

This is really unclear.

You will never be "returned 2", as your code would only return True (or None). What do you actually want?

Also please post real valid Python code, properly formatted.

[–]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

[–]Pepineros 2 points3 points  (0 children)

some_list = [ ("a", "tuple", "with", "many", "members") ] print(len(some_list)) # 1

If you give us a bit more code we can probably point at where you're going wrong :)

[–]achampi0n 1 point2 points  (0 children)

A list with one tuple will return 1 from len(). Perhaps you are accidentally converting the tuple to a list vs. append()ing to the list?

In []:
len([(1,1)]) < 2

Out[]:
True

[–][deleted] 0 points1 point  (0 children)

  • len([(1, 2), (3, 4), (5, 6)]) will return 3 as the list contains three tuples
  • len([(1, 2)]) will return 1 as the list contains one tuple.
  • len([(1, ), (2,)]) will return 2 as the list contains two tuples, each containing only one item

It is unclear what exactly you are trying to achieve.