03. [25p] Making the list

Solve these subtasks all in the same file (use print() statements to display the results):

Use the following list:

sample = ["a", 90, 8, "X55", "1z", 102, "asdf", 65, 10, "word", "567", 567]

Well:

  • Sort the list (does it work? if not, why?);
  • Reverse the list (this again? note: save the original one!);
  • Filter out all non-numbers from the list (i.e., only int type values should remain)… can you make it using a single line of code? now it's the time to introduce list comprehensions;

Don't know how to check the type of a variable? LMGTFY!

  • Print the original list (remember the first 2 subtasks? read this answer!);
  • Define a function that builds a matrix filled with numbers from 1 to n like the following example:
    m = [[1, 2, 3, 4],
         [4, 1, 2, 3],
         [3, 4, 1, 2],
         [2, 3, 4, 1]]
ii/labs/s2/01/tasks/03.txt · Last modified: 2024/03/15 13:30 by florin.stancu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0