Question: How to find sentences in text file that starts and ends with particular words for example sentences that starts with 'The' and ends with 'u'.I have tried

```
def main():
  f=open('D:\\file.txt')
  print 'The lines that starts with The and Ends with u'
  for line in f:
     for j in line.split('.'):
         if j[0]=='T' and j[1]=='h' and j[2]=='e' and j[3]==' ' and  j[-1]=='u':
            print j
if __name__ == '__main__':main()

```

Instead of character comparison can we do this using word comparison?

Answer: 
Python sets and dictionaries can both be constructed using curly braces:

`my_dict = {'a': 1, 'b': 2}`

`my_set = {1, 2, 3}`

The interpreter (and human readers) can distinguish between them based on their contents. However it isn't possible to distinguish between an empty set and an empty dict, so this case you need to use `set()` for empty sets to disambiguate.

A very simple test suggests that the literal construction is faster (python3.5):

```
>>> timeit.timeit('a = set([1, 2, 3])')
0.5449375328607857
>>> timeit.timeit('a = {1, 2, 3}')
0.20525191631168127

```

[This question](https://stackoverflow.com/questions/30216000/why-is-faster-than-list) covers some issues of performance of literal constructions over builtin functions, albeit for lists and dicts. The summary seems to be that literal constructions require less work from the interpreter.
`set([iterable])` is the constructor to create a set from the optional iterable `iterable`. And `{}` is to create set / dict object literals. So what is created depends on how you use it. 

```
In [414]: x = {}

In [415]: type(x)
Out[415]: dict

In [416]: x = {1}

In [417]: type(x)
Out[417]: set

In [418]: x = {1: "hello"}

In [419]: type(x)
Out[419]: dict

```