How to shuffle a list in Siri Shortcuts - sirishortcuts

I want to randomly permute a list using a default source of randomness. The only reference for "shuffle" that I've found is an option in the Play Music action.
In other words, how can I create an action that receives a list as an input and returns another list with the same elements, but in random order?

I was trying to shuffle a list of text items, and found the stupidest possible answer:
Use the "Filter Files" action on your list, even though it's not a list of files. Clear out any filters that are there. Then set "Sort by" to "Random."

Related

Where is the orange block that says 'Item (random) of list'? I am lost

I am taking an online coding course for beginners and we he is creating a randomizer that selects a random color from a list of colors that we created. I am trying to follow along step by step but I CANNOT find the orange block that he is using that says
'item (random) of list'. I found a similar orange block, but it doesn't have the 'random' dropdown option. Am I missing something here?
The dropdwn option there was removed in scratch 3.0 as far as I know, so that's probably the reason you can't find what you're looking for. What you still can do though is generate a random index to use there instead:
For a list of length n, that will choose a random number from 1 to n and then return the list element at that position, giving you a random element of that list.
This feature still exists. Although peabrainiac's answer was the simplest - you can also type the work "random" somewhere > copy it to your clipboard > paste it into the item of list. It will work the same. You must copy and paste it as it doesn't not support non-numeric values being entered directly.

UFT/QTP - Extract Values From List Within WebEdit

I am attempting to capture all the list items in the WebList elements throughout the entire application, however, while below code works on the WebLists, it does not work on this WebEdit.
When you click on the WebEdit, a long list of values appear (similar to a WebList) and as you type for your value, the list becomes shorter. That is how the WebEdit was set up.
But now, how do I get the values in this list?
Here is the code I have for the WebLists:
Code
Set WebLink = Browser("browser").Page("page")
listval = WebLink.WebElement("xpath:= ((//*[contains(text(), 'Name')]))[1]/following::SELECT[1]").GetROProperty("all items")
listvalues = split(listval,";")
For j = LBound(listvalues,1) To UBound(listvalues,1)
'Print listvalues(j)
writeToTextFile(listvalues(j))
Next
ExitTest
The short answer is: it depends on the implementation.
The long one:
There is no universal widget for comboboxes (Like there is for edit fields or lists / selects, radiobuttons etc) => there is no universal solution but only guidelines.
You need to spy on those objects that appear in the combobox, see their XPath and / or other properties (the css classname they belong to, for example) and then execute a second query that selects all such items. Afterwards you have to extract the value of the selected elements; which might be as simple as getting the innertext Property or you may need to dig even deeper in the HTML hierarchies.
You would need to pay careful attention for synchronisation(Waiting until all search result elements appear), Filtering (using the XPath, Description Objects and ChildObjects method on your WebPage) and then extraction( getting the property /element that contains the actual value of that WebElement)
So again: These combobox solutions are not universal therefore without seeing their code the best what one can provide to you is universal guidelines which should work in most of the situations. (You would need some familiarity with Web Programming and the UFT Framework / Robot)

How to create a list of lists with a specific width for the inner lists in prolog?

I'm trying to create a list of lists where my input is a large flattened grid and i need to take the elements in the grid and resize them into smaller lists.
For example, I have a list like this : [1,2,3,4,5,6,7,8] and I want to create the list of lists to be [[1,2,3,4],[5,6,7,8]] where I resized the elements in each inner list to the width (4) in this case. If my list had only 7 elements then the result should be [[1,2,3,4]] and I should disregard the rest since they won't form another list of width 4. Here is my code, I am having trouble with "out of global stack" error and I can't figure it out.
code:
list_to_llists([],W,L).
list_to_llists([H|T],W,[[X1]|[Xr]]):-
length([X1],R),
R<W,
append(X1,H,Rs),
list_to_llists(T,W,Rs).
list_to_llists([H|T],W,[[X1]|[Xr]]):-
length([X1],R),
R>=W,
append(Xr,H,Rs),
list_to_llists(T,W,Xr).
list_to_llists(L,W,[S|R]):-
length(S,W),
append(S,T,L),
!, list_to_llists(T,W,R).
list_to_llists(L,_,[L]).
length(S,W) generates a list of free variables, hence, if such list can be a prefix, just store in results.
You can also try without the cut, to better understand the behaviour.

Replace List Item Appinventor

I have a TinyDB and in each tag of the TinyDB I have a list.
Each list has 3 items, each indexed as 1, 2 and 3.
I want to change the 3rd item, index 3.
So I have done the following
So I want to now save the change in the TinyDB
and have added a storeValue command as follows.
I figured out how to get the valuetoStore variable. As follows.
I had done this before, and thought it wrong because it still doesn't change the 3rd item in the list. But I've added a notifier to look at it and it's correct. So the "replace list item" isn't working how I thought it should. It isn't replacing the 3rd item with an "n."
Any ideas?
Thanks.
Your second try is almost correct. The only thing is, you should use the replace list item block together with the local variable name instead of retrieving the value again from TinyDB.
So what is the difference to your "solution"? Currently you assign the list to a local variable name. Then you use the replace list item block together with a list, you can't store somewhere (you are loading the list again from TinyDB). And in the end you store variable name (which doesn't have been modified at all) in TinyDB. Therefore the solution is to use the replace list item block together with the local variable name instead of retrieving the value again from TinyDB. Btw. a better name for the local variable name would be list.
Further tips
Also in the definition of the local variable name you should add a block, e.g. an empty string or 0
And if you want simplify a little bit, you can move the definition of the local variable name inside the for each loop. And alternatively of using the for each number loop, for list it's easier to use the for each item in list loop, see also the documentation. The list in your case is TinyDB1.GetTags.
As already said in the forum, generally I would use a list of lists and store it in only one tag in TinyDB
How to work with Lists by Saj
How to work with Lists and Lists of lists (pdf) by appinventor.org

In Yahoo! Pipes how can I return a single value from a loop that's built with values from every item?

For example, I have a list of items and each item has a name. I want to build a single string that contains a comma-separated list of all the names. In most programming languages, I would loop over the items and append to a value outside the list/array. But, I can't figure out any combination of Yahoo! Pipes modules to do it. Maybe I'm missing something obvious, but I also find nothing relevant from Google.
How do I append loop item values to a single value outside the loop?
Or how can I return a single value from a loop that's built with values from every item?
Or what is the correct method to accomplish this in Pipes if it's neither of those?
The best method I've come up with based on help from the Yahoo! group, is to use an Item Builder (item.string = default) --> Loop ( assign all to item.string ). Using another pipe inside the Loop to provide the values to concatenate was also very helpful.
Unfortunately the modules available with Yahoo Pipes alone cannot perform the task you are aiming at. The only solution available currently is to use "web service" module to call an externally hosted script (say in PHP)... the entire pipe content will be sent to the script as POST field "data". You can code the script such that it loops through all items to add the string to a single string and return it after processing.

Resources