tuples

Oracle invalid identifier doesnt understand string

自古美人都是妖i 提交于 2019-12-02 10:31:00
问题 I'm having an issue with my query not working. This is the command variable. When it executes it should be retrieving the tuples that have BSc as their degree. I have tested this in oracle directly and the query returns these. It is identical to the command statement. When I print out command , the line looks exactly the same as my command that worked in oracle. SELECT distinct fname, lname, student_id FROM student where degree='BA'; Yet, it should be printing out to the screen. The tables

Swift Tuple index using a variable as the index?

我是研究僧i 提交于 2019-12-02 09:47:08
问题 Swift Tuple index using a variable as the index? Anyone know if it is possible to use a variable as the index for a Swift tuple index. I wish to select and item from a tuple using a random number. I have the random number as a variable but cannot see how to use that as the index for a tuple. I have searched various places already 回答1: Make sure you've chosen the correct data structure If you've reached a point where you need to access tuple members as if "indexed", you should probably look

Converting a list of ints, tuples into an numpy array

徘徊边缘 提交于 2019-12-02 08:47:40
I have a list of [float, (float,float,float..) ] ... Which is basically an n-dimensional point along with a fitness value for each point. For eg. 4.3, (2,3,4) 3.2, (1,3,5) . . 48.2, (23,1,32) I wish to randomly sample one point based upon the fitness values. I decided the best way to do this would be to use numpy.random.choice(range(n), 1, plist[:,:1,:1]) However, i need to convert this into an numpy array, for which i tried >> pArr = np.array( plist ) ValueError: setting an array element with a sequence I got the same error for np.asarray(plist) as well.. any suggestions?? The following

How to get the key from a given name in dictionary in python

对着背影说爱祢 提交于 2019-12-02 08:28:32
I have a variable called anime_dict which contains a dictionary of lists of objects as shown below. {'JI2212': ('Inu Yasha', [('year', 1992), ('rating', 3)]), 'EH389J': (Naruto', [('year', 1994), ('rating', 4), ('readers', 3424322)]), 'PPP67': ('Fruits Basket', [('Year', 1999), ('rating', 5), ('readers', 434232), ('chap', 40)])} so the key of the dict is the 1st part ('JI2212' for Inu Yasha), the 2nd part is the name and the last part contains a list of parts. I want to create 2 functions that would 1st get the key from the given name and 2nd get the parts from the given name. the functions

Convert a list into a sequence of string triples

守給你的承諾、 提交于 2019-12-02 08:01:55
问题 I'd like to convert a list like: ["Red", "Green", "Blue"] into a tuple sequence of string triples: [("RED", "Red", ""), ("GREEN", "Green", ""), ("BLUE", "Blue", "")] Until now I always use this method: def list_to_items(lst): items = [] for i in lst: items.append((i.upper(), i, "")) return items But it feels a bit ugly. Is there a nicer / more pythonic way of doing this? 回答1: You can use a comprehension: def list_to_items(lst): return [(item.upper(), item.title(), '') for item in lst] 回答2:

convert tuple keys of dict into a new dict

痞子三分冷 提交于 2019-12-02 07:56:13
问题 I have a dict like this: { ('America', 25, 'm', 'IT'): 10000, ('America', 22, 'm', 'IT'): 8999, ('Japan', 24, 'f', 'IT'): 9999, ('Japan', 23, 'f', 'IT'): 9000 } Now, I want to get all result with key ('America', 'm', 'IT') , in this example. In the above, that would be: {25: 10000, 22: 8999} My current solution is below: res = dict() for key, cnt in stats.items(): country, age, sex, job = key try: res[(country, sex, job)][age] = cnt except KeyError as e: res[(country, sex, job)] = {} res[

How to add elements individually in tuple?

北城以北 提交于 2019-12-02 07:25:41
问题 How to add elements individually within the tuple? For example, i need (2, 4) from (0,1) + (2,3) , I've been doing it as such but is there a more pythonic / less verbose way to do the same? >>> x = (0,1) >>> y = (2,3) >>> x + y (0, 1, 2, 3) >>> tuple(i+j for i,j in zip(x,y)) (2, 4) 回答1: You can use zip and sum here: Example: >>> x = (0, 1) >>> y = (2, 3) >>> tuple(map(sum, zip(x, y))) (2, 4) zip lets us combine elements of two iterables or lists in pairs. sum lets us sum the pairs map lets us

How to add elements individually in tuple?

蓝咒 提交于 2019-12-02 07:24:17
How to add elements individually within the tuple? For example, i need (2, 4) from (0,1) + (2,3) , I've been doing it as such but is there a more pythonic / less verbose way to do the same? >>> x = (0,1) >>> y = (2,3) >>> x + y (0, 1, 2, 3) >>> tuple(i+j for i,j in zip(x,y)) (2, 4) James Mills You can use zip and sum here: Example: >>> x = (0, 1) >>> y = (2, 3) >>> tuple(map(sum, zip(x, y))) (2, 4) zip lets us combine elements of two iterables or lists in pairs. sum lets us sum the pairs map lets us apply the sum function per pair. finally we convert the resulting list ( or iterable in Python

Convert a list into a sequence of string triples

别说谁变了你拦得住时间么 提交于 2019-12-02 07:17:11
I'd like to convert a list like: ["Red", "Green", "Blue"] into a tuple sequence of string triples: [("RED", "Red", ""), ("GREEN", "Green", ""), ("BLUE", "Blue", "")] Until now I always use this method: def list_to_items(lst): items = [] for i in lst: items.append((i.upper(), i, "")) return items But it feels a bit ugly. Is there a nicer / more pythonic way of doing this? You can use a comprehension: def list_to_items(lst): return [(item.upper(), item.title(), '') for item in lst] Similar to list comprehension, but a bit different. This is the map function. lst = ["Red", "Green", "Blue"] new

Sorting dict items by key, beyond alphanumeric sorting

为君一笑 提交于 2019-12-02 06:48:31
问题 I have written this code: n=5 dizN={} for q in range(0,n+1): h=n-q dizN['a'+str(q)+'p'+str(h)]=0 that creates such a dictionary: dizN Out[120]: {'a0p5': 0, 'a1p4': 0, 'a2p3': 0, 'a3p2': 0, 'a4p1': 0, 'a5p0': 0} Note that "n" is the basic parameter for my code. As you can see, the sum of integers present in dict keys string is always =n (=5 in this case, where n=5). It is important for me (for more difficult purposes in my program) that, for every n anyone can choose, the dict is ordered in