colores = ["rojo","azul","morado"]
color_fav = "negroo"9 Built-in functions
[color for color in colores if len(color)==4]['rojo', 'azul']
colores.count("rojo")1
color_fav.count("o")2
color_fav.upper()'NEGROO'
colores.upper()--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[9], line 1 ----> 1 colores.upper() AttributeError: 'list' object has no attribute 'upper'
https://docs.python.org/3/library/functions.html
abs?Signature: abs(x, /) Docstring: Return the absolute value of the argument. Type: builtin_function_or_method
abs(-1)1
list(enumerate(colores))[(0, 'rojo'), (1, 'azul'), (2, 'morado')]
## NO debo hacer esto
for i,color in enumerate(colores):
print(i,colores[i])0 rojo
1 azul
2 morado
## Llevar la cuenta
for i,color in enumerate(colores):
print(i,color)0 rojo
1 azul
2 morado
len(colores)3
colores = [
["rojo","azul"],
["azul"]
]
personas = [
"michel",
"yadira",
"laura"
]len(colores)2
len(colores[0])2
len(colores[1])1
len(personas)2
zip?Init signature: zip(self, /, *args, **kwargs) Docstring: zip(*iterables, strict=False) --> Yield tuples until an input is exhausted. >>> list(zip('abcdefg', range(3), range(4))) [('a', 0, 0), ('b', 1, 1), ('c', 2, 2)] The zip object yields n-length tuples, where n is the number of iterables passed as positional arguments to zip(). The i-th element in every tuple comes from the i-th iterable argument to zip(). This continues until the shortest argument is exhausted. If strict is true and one of the arguments is exhausted before the others, raise a ValueError. Type: type Subclasses:
list(zip(personas,colores))[('michel', ['rojo', 'azul']), ('yadira', ['azul'])]
for persona_color in zip(personas,colores):
print(persona_color)('michel', ['rojo', 'azul'])
('yadira', ['azul'])
[persona_color for persona_color in zip(personas,colores)][('michel', ['rojo', 'azul']), ('yadira', ['azul'])]
range?Init signature: range(self, /, *args, **kwargs) Docstring: range(stop) -> range object range(start, stop[, step]) -> range object Return an object that produces a sequence of integers from start (inclusive) to stop (exclusive) by step. range(i, j) produces i, i+1, i+2, ..., j-1. start defaults to 0, and stop is omitted! range(4) produces 0, 1, 2, 3. These are exactly the valid indices for a list of 4 elements. When step is given, it specifies the increment (or decrement). Type: type Subclasses:
range(0,10)range(0, 10)
for i in range(0,10):
print(i)0
1
2
3
4
5
6
7
8
9
for i in range(0,10,2):
print(i)0
2
4
6
8
# Mala practica
for i in range(len(colores)):
print(i)0
1
for i,color in enumerate(colores):
print(i)0
1
for i,_ in enumerate(colores):
print(i)0
1
min?Docstring: min(iterable, *[, default=obj, key=func]) -> value min(arg1, arg2, *args, *[, key=func]) -> value With a single iterable argument, return its smallest item. The default keyword-only argument specifies an object to return if the provided iterable is empty. With two or more arguments, return the smallest argument. Type: builtin_function_or_method
min(colores)['azul']
min(personas)'laura'
max(colores)['rojo', 'azul']
max([1,2,4,2000,10])2000
sum([1,2,4,5])12
sum(personas)--------------------------------------------------------------------------- TypeError Traceback (most recent call last) Cell In[62], line 1 ----> 1 sum(personas) TypeError: unsupported operand type(s) for +: 'int' and 'str'
personas.pop?Signature: personas.pop(index=-1, /) Docstring: Remove and return item at index (default last). Raises IndexError if list is empty or index is out of range. Type: builtin_function_or_method
dir(__builtin__)['ArithmeticError',
'AssertionError',
'AttributeError',
'BaseException',
'BaseExceptionGroup',
'BlockingIOError',
'BrokenPipeError',
'BufferError',
'BytesWarning',
'ChildProcessError',
'ConnectionAbortedError',
'ConnectionError',
'ConnectionRefusedError',
'ConnectionResetError',
'DeprecationWarning',
'EOFError',
'Ellipsis',
'EncodingWarning',
'EnvironmentError',
'Exception',
'ExceptionGroup',
'False',
'FileExistsError',
'FileNotFoundError',
'FloatingPointError',
'FutureWarning',
'GeneratorExit',
'IOError',
'ImportError',
'ImportWarning',
'IndentationError',
'IndexError',
'InterruptedError',
'IsADirectoryError',
'KeyError',
'KeyboardInterrupt',
'LookupError',
'MemoryError',
'ModuleNotFoundError',
'NameError',
'None',
'NotADirectoryError',
'NotImplemented',
'NotImplementedError',
'OSError',
'OverflowError',
'PendingDeprecationWarning',
'PermissionError',
'ProcessLookupError',
'RecursionError',
'ReferenceError',
'ResourceWarning',
'RuntimeError',
'RuntimeWarning',
'StopAsyncIteration',
'StopIteration',
'SyntaxError',
'SyntaxWarning',
'SystemError',
'SystemExit',
'TabError',
'TimeoutError',
'True',
'TypeError',
'UnboundLocalError',
'UnicodeDecodeError',
'UnicodeEncodeError',
'UnicodeError',
'UnicodeTranslateError',
'UnicodeWarning',
'UserWarning',
'ValueError',
'Warning',
'WindowsError',
'ZeroDivisionError',
'__IPYTHON__',
'__build_class__',
'__debug__',
'__doc__',
'__import__',
'__loader__',
'__name__',
'__package__',
'__spec__',
'abs',
'aiter',
'all',
'anext',
'any',
'ascii',
'bin',
'bool',
'breakpoint',
'bytearray',
'bytes',
'callable',
'chr',
'classmethod',
'compile',
'complex',
'copyright',
'credits',
'delattr',
'dict',
'dir',
'display',
'divmod',
'enumerate',
'eval',
'exec',
'execfile',
'filter',
'float',
'format',
'frozenset',
'get_ipython',
'getattr',
'globals',
'hasattr',
'hash',
'help',
'hex',
'id',
'input',
'int',
'isinstance',
'issubclass',
'iter',
'len',
'license',
'list',
'locals',
'map',
'max',
'memoryview',
'min',
'next',
'object',
'oct',
'open',
'ord',
'pow',
'print',
'property',
'range',
'repr',
'reversed',
'round',
'runfile',
'set',
'setattr',
'slice',
'sorted',
'staticmethod',
'str',
'sum',
'super',
'tuple',
'type',
'vars',
'zip']