thanks for your time and attention on this beginner's issue
The book I've read claims that "You can use the first and last propeties, which return one of the elements in the set"
However, I've tried it and seems it is not working. I would very appreciate if someone can explain it for me.
You cannot ask for the last item of a Set. Indeed, a Set is not ordered, so there is not last item (nor last property).
Don't hesitate to take a look at the Swift Doc on Set.
If you want to find the last element, you need an ordered collection like an Array:
var myArray = [1, 2, 3, 4, 5]
print(myArray.last) // Display 5
Related
I am fairly new to Redis and RedisJson and I have been through all the documentation I can get my hands on, but I still can't seem to figure this one out. I am hoping someone could shed some light on this situation to help me understand. My end goal is to be able to remove the JSON object from the responses array using JSON.ARRPOP. I need to get the index of the object first and I can't seem to do that.
Here is my object structure:
JSON.SET test:1 $ '{ "responses":[{"responseId":"29aab59c-10b0-48c0-ab91-8873fb6e2238"},{"responseId":"ab79f09b-8e31-41f4-9191-ef89a34964d3"}]}'
Check the path:
JSON.GET test:1 $.responses[*].responseId
RETURNS:
"["29aab59c-10b0-48c0-ab91-8873fb6e2238","ab79f09b-8e31-41f4-9191-ef89a34964d3"]"
Ok looks good I have an array of two strings lets get that index of 29aab59c-10b0-48c0-ab91-8873fb6e2238.
JSON.ARRINDEX test:1 $.responses[*].responseId '"29aab59c-10b0-48c0-ab91-8873fb6e2238"'
RETURNS:
(nil)
(nil)
It appears to have searched but found nothing?
At first I thought it was an escape character issue but I get the same results with responeIds as integers 1 and 2.
Any help here would be greatly appreciated. Thanks!
JSON.ARRINDEX can only search for scalar values. Objects and arrays are not scalars so you can't search for them.
For your use case you should look at https://redis.io/docs/stack/search/indexing_json/
I am currently a student in high school. Due to the fact that my state is on complete shutdown because of the whole COVID-19 crisis that is going on. I am trying to add 2 functions into a range of cells to further organize myself while trying my best to stay organized doing school from home.
Function 1: =DAYS(E:E,TODAY()) Count how many days left to complete an assignment.
Function 2: =IF(E:E=-1, "PAST DUE") If the amount of days left equals -1, it will change the cell text to "PAST DUE".
The only problems I am having is A: Combining 2 functions, and B: making the IF statement work. If there is any way you could help me out, then please try. It would mean a whole lot.
=IF(DAYS(E:E,TODAY())<0, "PAST DUE", DAYS(E:E,TODAY()))
If {days left} is less than 0, then return "PAST DUE". Otherwise, return {days left}
Something like this?
=IF(DAYS(E:E,TODAY())<=-1, "PAST DUE", DAYS(E:E,TODAY()))
try for array:
=ARRAYFORMULA(IF(DAYS(E1:E, TODAY())<0, "PAST DUE", DAYS(E1:E, TODAY())))
In jasper I have to print a collection without knowing in advance the keys, because they are programmatic and can change over time. Let me do an example of this list:
formData[0]={addictions=1, workout=0, allergies=1, selfSufficiency=0}
formData[1]={gastricNose=1, weightChange=1, diet=XXXX}
[...]
formData[12]={dailyAmount=12, latestDate={type=date, value=1542582000000}, ostomy=1, ostomyType=AA, ostomyBag=BB}
How can I print a list of all these keys/values so that they get all listed properly like this? I can already print these objects raw in a list but they obviously look pretty much like the example I wrote above, while instead I need jasper to cycle through each of the elements by itself and retrieve the keys and the value for each element.
This is what I'm trying to print:
addictions: 1
workout: 0
[...]
gastricNose: 1
weightChange: 1
[...]
dailyAmount: 12
latestDate: 18/11/2018
[...]
In all posts I've looked into I'm required to know at least the name of the keys, but in my case I can't. And I cannot modify the data source structure either (for instance formatting the collection to be {key:"addictions",value:"1"} can't do that).
Thanks for your hints
I'm trying to do a very easy task, add an item to a dictionary using "append".
This is the dict:
var myDictionary: [String:Int] = [
"Apple" : 1,
"Banana" : 2,
"Strawberry" : 3
]
I've tried this
myDictionary+=["Raspberry":4]
Here I get the error message:
binary operator cannot be apllied to two operands
and also I tried:
myDictionary.append("Raspberry":4)
and
myDictionary.append[("Raspberry":4)]
as well, but I get the error that it has :
no member 'append.
What exactly is the problem, how could I add the 4th item ?
Thanks for your help
append is the wrong tool here. You just want to set the value:
myDictionary["Raspberry"] = 4
append applies to things that conform to RangeReplaceableCollection. Dictionary does not. When you insert new things into a dictionary, they are not being appended to the end. They're being inserted into the appropriate buckets (perhaps replacing things already in place). If you use append to add something, you should reasonably expect last to then return that thing, but that's not promised (or even very likely) in a dictionary. Set is similar, and also has no append.
I am new to python.I am posting here for the first time and I know question might be quite basic but problem is I can't figure out myself.
Lets say I have
List=[("a,"b"),("c","d"),("e","f")]
I want the user to enter one of the elements of one of the tuples as input and the other element is printed.Or more precisely I would say that just one of elements in List[x][0] is input and corresponding List[x][1] element is printed as output.I hope it makes sense.
Thanks!
Please check List in the question.I think you forgot a quote(") in the first tuple.[("a^here,"b"),("c","d"),("e","f")]
I think this might help you.
List=[("a","b"),("c","d"),("e","f")]
c=raw_input('ENTER A CHARACTER-')
for i in xrange(len(List)):
if c in List[i]:
ind=List[i].index(c)
print List[i][abs(ind-1)]
break