Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • CreatiCode
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

CreatiCode Scratch Forum

  1. CreatiCode Forum
  2. Knowledge Base
  3. 2D Blocks
  4. Working with Lists

Working with Lists

Scheduled Pinned Locked Moved 2D Blocks
1 Posts 1 Posters 896 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CreatiCodeI Offline
    CreatiCodeI Offline
    CreatiCode
    wrote on last edited by admin
    #1

    Introduction

    You have learned how to make a list, edit the items in it, and read data from it. This article will cover some more advanced blocks for working with a list.

     
     

    Sorting a List

    To sort a list’s items, you can use the following block:

    w.gif

     
    Note that you can use this block for lists with text items as well. The first letter of each item will be used for comparison. For example, the word “Abby” is treated as smaller than the word “Bob”, since the letter “A” comes before “B” in the alphabet.

    When 2 items have the same first letter, then the second letter is used. For example, “Bob” is treated as smaller than “Brain”, since they both start with “B”, and “o” comes before “r” in the alphabet.

    Note that the upper case or lower case of the letters will be treated as the same.

    s1.gif

     
     

    Reshuffle a List Randomly

    You can assign a random position to each item in the list by “reshuffling” the list, similar to how we reshuffle a deck of cards.

    w.gif

     
    For another example, suppose you need to print out the name of every student in the cla*s, but you want to make it random so no one can guess who will be next. You just need to reshuffle the list of names.

    w.gif

     
     

    Reverse a List

    You can reverse a list using the “reverse” block. The first item will become the last, and the second item will become the second last, etc. If you reverse a list 2 times, you should get exactly the same list.

    s2.gif

     
     

    Join List Items into String

    You can join all items in a list together into one long string, and you can specify a separator that will be placed between these items.

    s3.gif

     
     

    Split a String into List Items

    The opposite of “joining” is splitting. You can split a long string into individual items, and you can specify which separator to use.

    s4.gif

     
     

    Append One List to Another List

    You can append a list to another list, which means adding all the items from a list to the bottom of another list. For example, when you append “numbers2” to “numbers”, the list “numbers2” won’t change, but its 3 items will be appended to the bottom of “numbers”.

    s5.gif

     
     

    Copy from One List to Another List

    You can also copy from one list to another list. The original items of the target list will be removed first, so after this operation, both lists have the same items:

    s6.gif

     
     

    Generate a Random List of Numbers

    The “pick random” block in the “Operators” category will produce a random number within a random. If you want to generate a list of random numbers, you can use the following block.

    Note that if you allow repetition, then the same number may be used more than once. If you do not allow repetition, then a number will not be used if is already in the list.

    s7.gif

     
     

    Iterate Through a List

    You can go through a list and check every item in the list.

    First, you can use the “for each item in list” block, which assigns the variable with the value of each item in the list:

    https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/0d9821f6-08a3-4ffe-9b1d-cf9db74776b7.gif" width="800" style="border-radius: 5px; border: 1px solid #29622d;">

     
    You can also use an index variable to visit every item in the list. The index variable will go from 1 up until it is equal to the length of the list. You can use this variable to read from the list inside this loop:

    s9.gif

    1 Reply Last reply
    0

    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

    With your input, this post could be even better 💗

    Register Login
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode